<template>
  <div
    class="page_root"
    :key="queryUpdateFlag"
    data-page-name="交付项目任务列表"
    data-page-identification="a_zo45cjbhlx"
  >
    <a-spin :spinning="pageLoading.loading" :tip="pageLoading.tip">
      <!-- begin vid_nvbvgxjzfj 自定义模板_7gpu8ebdx3 -->
<!--      自动化任务完成弹窗-->
      <a-modal v-model:visible="statuState.autComplateVisible" title="完成自动化任务" centered :mask-closable="false" :keyboard="false" width="800px" @ok="autoComplateSubmit" @cancel="cancelAutoComplate">
        <div
          style="border-bottom: 1px solid #d9d9d9; margin-bottom: 10px"
          class="wcrw"
        >
          <a-col :span="24">
            <a-form-item label="实际起止时间">
              <a-range-picker
                show-time
                style="width: 360px"
                v-model:value="jfMbActualFinishTime"
                value-format="YYYY-MM-DD HH:mm:ss"
              />
            </a-form-item>
          </a-col>
        </div>

        <template #footer>
          <a-button key="back" type="primary" @click="downLoadTemplate"
          >下载模板</a-button
          >
          <a-button key="back" @click="cancelAutoComplate"
          >取消</a-button
          >
          <a-button
            key="submit"
            type="primary"
            :loading="templateOkDisabled"
            @click="autoComplateSubmit"
          >
            {{ uploadLoading ? "附件上传中请稍后.." : "提交审批" }}</a-button
          >
        </template>
        <a-radio-group v-model:value="statuState.radioValue" style="margin-bottom: 10px" @change="autoRadioChange">
          <a-radio value="默认参数">默认参数</a-radio>
          <a-radio value="自定义参数">自定义参数</a-radio>
        </a-radio-group>
       <div v-if="statuState.radioValue==='默认参数'">
         <p style=";white-space: pre-wrap">
           默认参数:<br/>
           时间范围：默认状态下，自动获取最近生产(开窑开磨)1天数据，不含报告执行当天，取用完整自然日；<br/>
           文件名：取所有主数据映射的点位(本地主数据)；
         </p>
       </div>
        <div v-else>
          <a-textarea v-model:value="statuState.repParams" :rows="8"></a-textarea>
          <p style="margin-top: 12px;white-space: pre-wrap">
            参数描述:
            {{autoTask.verifyComment}}
          </p>
        </div>
        <a-spin :spinning="uploadLoading" tip="附件上传中...">
          <a-upload
            :file-list="stateLi.fileList"
            :multiple="true"
            :before-upload="handlerUpload"
            @remove="handleRemove"
            accept=".xlsx,.ppt,.pdf,.PDF, image/*, .docx, .rp, .xls"
          >
            <a-button type="primary">
              <upload-outlined />
              上传
            </a-button>
          </a-upload>
          <span>支持格式：image/*,.xlsx,.xls,.docx,.rp,.ppt,.pptx,.pdf</span>
        </a-spin>

      </a-modal>
<!--      自动化任务完成弹窗-->
      <!--FAQ-->
      <a-modal
        v-model:visible="faqVisible"
        title="FAQ"
        width="80%"
        :footer="null"
        centered
        @cancel="faqVisibleCancel"
      >
        <a-table
          :columns="faqColumns"
          :data-source="faqDataSource"
          bordered
          :scroll="{ y: 630 }"
          :pagination="false"
        >
        </a-table>
      </a-modal>

      <!--任务隐藏-->
      <a-modal
        v-model:visible="isTaskShow.taskShowVisible"
        :title="isTaskShow.showTitle"
        @ok="showOrHideTask"
        centered
        @cancel="taskShowCancel"
      >
        <p>被隐藏的任务将取消一切任务加减分；</p>
        <p>任务恢复后将根据计划结束时间重新计算加减分，请通过编辑及时变更；</p>
        <p>是否确认{{ isTaskShow.text }}？</p>
      </a-modal>
      <!--任务隐藏-->
      <!--                      批量延时-->
      <a-modal
        v-model:visible="batchDelay.delayVisible"
        title="批量延时"
        centered
        width="800px"
        @ok="confirmDelay"
        @cancel="batchDelayCancel"
        :ok-button-props="{ loading: dailyLoading }"
        :body-style="{
          paddingBottom: 0,
        }"
      >
        <p>
          请输入批量延时天数，确认后该任务以及所有设置该任务为依赖任务的非完成状态任务（含这些任务的被依赖任务）将全部按照天数（排除节假日、周日）向后调整计划开始和结束时间；<br />
          PMO手动调整无需审批，项目总监、项目经理手动调整后需通过PMO审批；<br />
          所有通过批量延时改变计划开始和结束时间的任务，提前完成将不再加分；<br />
          所有通过批量延时改变计划开始和结束时间的任务，将通过新的计划开始时间判断任务的延期未启动天数加减分<br />
          所有通过批量延时改变计划开始和结束时间的任务，将通过新的计划结束时间判断任务的延期加减分；<br />
          所有通过批量延时改变计划开始和结束时间的任务，如果加减分已通过月度绩效结算发放工资不会进行补加补减；<br />
        </p>
        <div class="batch-line"></div>
        <a-form :model="batchDelay.model" ref="batchDelayRef">
          <a-row>
            <a-col :span="12">
              <a-form-item
                label="延期天数"
                :rules="[
                  {
                    required: true,
                    message: '请输入延期天数',
                    trigger: 'blur',
                  },
                ]"
                name="count"
              >
                <a-input-number
                  v-model:value="batchDelay.model.count"
                  style="width: 100%"
                ></a-input-number>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </a-modal>
      <!--                      批量延时-->
      <a-modal
        v-model:visible="stateLi.visible"
        :title="`${
          current.taskId ? (current.restore ? '恢复' : '修改') : '新增'
        }任务`"
        destroyOnClose
        centered
        width="50%"
        :ok-button-props="{ disabled: btnLoading }"

        @cancel="handlerCancel"
        @ok="beforeSubmit"
      >
        <a-form ref="formRef" :model="stateLi.ppmTaskFromList" class="modal-form">
          <div
            v-for="(item, index) in stateLi.ppmTaskFromList"
            :key="index"
            class="form-item"
          >
            <div class="form-content">
              <a-row class="one-line">
                <a-col :span="24">
                  <a-form-item
                    label="任务类型"
                    :name="[index, 'nodeType']"
                    :rules="{ required: true, message: '请选择任务类型!' }"
                  >
                    <a-select
                      v-model:value="stateLi.ppmTaskFromList[index].nodeType"
                      :disabled="current.taskId"
                      showSearch
                      :options="[
                        {
                          label: '父级任务',
                          value: 'MENU',
                        },
                        {
                          label: '子任务',
                          value: 'TASK',
                        },
                      ]"
                    />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="12">
                  <a-form-item
                    label="任务名称"
                    :name="[index, 'taskName']"
                    :rules="{ required: true, message: '请输入任务名称!' }"
                  >
                    <a-input
                      placeholder="请输入任务名称"
                      v-model:value="stateLi.ppmTaskFromList[index].taskName"
                      :disabled="isTemplate"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="12">
                  <a-form-item
                    label="任务优先级"
                    :name="[index, 'priority']"
                    :rules="{ required: true, message: '请选择任务优先级!' }"
                  >
                    <a-select
                      placeholder="请选择任务优先级"
                      v-model:value="stateLi.ppmTaskFromList[index].priority"
                      showSearch
                      :options="[
                        { label: '最高', value: 'HIGHEST' },
                        { label: '高', value: 'HIGH' },
                        { label: '中', value: 'MEDIUM' },
                        { label: '低', value: 'LOW' },
                        { label: '最低', value: 'LOWEST' },
                      ]"
                    />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="12">
                  <a-form-item
                    label="项目阶段"
                    :name="[index, 'milepostId']"
                    :rules="{ required: true, message: '请选择项目阶段!' }"
                  >
                    <a-select
                      placeholder="请选择项目阶段"
                      v-model:value="stateLi.ppmTaskFromList[index].milepostId"
                      showSearch
                      :options="stateLi.milepostList"
                      :field-names="{
                        label: 'milepostName',
                        value: 'milepostId',
                      }"
                      @focus="getMilepostList"
                      @change="handlerMilepostIdChange(index)"
                      :filter-option="
                        (input, option) => {
                          return (
                            option.milepostName
                              .toLowerCase()
                              .indexOf(input.toLowerCase()) >= 0
                          );
                        }
                      "
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="12">
                  <a-form-item label="父级任务">
                    <a-tree-select
                      placeholder="请选择父级任务"
                      v-model:value="stateLi.ppmTaskFromList[index].parentId"
                      allowClear
                      showSearch
                      :tree-data="stateLi.parentListMap[index]"
                      :field-names="{ label: 'taskName', value: 'taskId' }"
                      :filter-option="
                        (input, option) => {
                          return (
                            option.taskName
                              .toLowerCase()
                              .indexOf(input.toLowerCase()) >= 0
                          );
                        }
                      "
                    />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row class="one-line">
                <a-col :span="24">
                  <a-form-item
                    label="任务序号"
                    :name="[index, 'taskIndex']"
                    :rules="{ required: true, message: '请输入任务序号!' }"
                  >
                    <a-input
                      placeholder="请输入任务序号"
                      v-model:value="stateLi.ppmTaskFromList[index].taskIndex"
                      :min="0"
                      type="number"
                    />
                  </a-form-item>
                </a-col>
              </a-row>
              <template
                v-if="stateLi.ppmTaskFromList[index].nodeType === 'TASK'"
              >
                <a-row class="one-line"> </a-row>
                <a-row>
                  <a-col :span="12">
                    <a-form-item label="依赖任务">
                      <a-select
                        placeholder="请选择依赖任务"
                        v-model:value="
                          stateLi.ppmTaskFromList[index].taskDependency
                        "
                        allowClear
                        showSearch
                        :options="stateLi.taskList"
                        @focus="getTaskList()"
                        :field-names="{ label: 'taskName', value: 'taskId' }"
                        :filter-option="
                          (input, option) => {
                            return (
                              option.taskName
                                .toLowerCase()
                                .indexOf(input.toLowerCase()) >= 0
                            );
                          }
                        "
                      />
                    </a-form-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-item
                      label="任务类型"
                      :name="[index, 'taskType']"
                      :rules="{ required: true, message: '请选择任任务类型!' }"
                    >
                      <a-select
                        placeholder="请选择任务类型"
                        v-model:value="stateLi.ppmTaskFromList[index].taskType"
                        showSearch
                        :options="[
                          { label: '主任务', value: '主任务' },
                          { label: '辅助任务', value: '辅助任务' },
                          { label: '其他任务', value: '其他任务' },
                        ]"
                      />
                    </a-form-item>
                  </a-col>
                </a-row>

                <a-row>
                  <a-col :span="12">
                    <a-form-item
                      label="预计投入工时"
                      :name="[index, 'workingHours']"
                      :rules="[
                        {
                          required: true,
                          message: '请输入预计投入工时!',
                          trigger: 'blur',
                        },
                        {
                          pattern: /^(0\.5|[1-9](\d*)?(\.5)?(\.0)?)$/,
                          message: '请输入大于0的数字(支持0.5的倍数)',
                          trigger: 'blur',
                        },
                      ]"
                    >
                      <a-input
                        placeholder="请输入工时(支持0.5的数字)"
                        v-model:value="
                          stateLi.ppmTaskFromList[index].workingHours
                        "
                        type="number"
                        suffix="小时"
                      />
                    </a-form-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-item
                      label="任务起止时间"
                      :name="[index, 'allTime']"
                      :rules="{
                        required: true,
                        message: '请选择任务起止时间!',
                      }"
                    >
                      <a-range-picker
                        v-model:value="stateLi.ppmTaskFromList[index].allTime"
                        valueFormat="YYYY-MM-DD"
                      />
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="12">
                    <a-form-item
                      label="任务负责人"
                      :name="[index, 'taskOwner']"
                      :rules="{ required: true, message: '请选择任务负责人!' }"
                    >
                      <a-select
                        placeholder="请选择任务负责人"
                        v-model:value="stateLi.ppmTaskFromList[index].taskOwner"
                        showSearch
                        :options="peopleList"
                        :field-names="{ label: 'label', value: 'value' }"
                        :filter-option="
                          (input, option) => {
                            return (
                              option.label
                                .toLowerCase()
                                .indexOf(input.toLowerCase()) >= 0
                            );
                          }
                        "
                      />
                    </a-form-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-item
                      label="是否必须提交输出物"
                      :name="[index, 'output']"
                      :rules="{
                        required: true,
                        message: '请选择是否必须提交输出物!',
                      }"
                    >
                      <a-select
                        placeholder="请选择是否必须提交输出物"
                        v-model:value="stateLi.ppmTaskFromList[index].output"
                        showSearch
                        :options="[
                          { label: '是', value: '是' },
                          { label: '否', value: '否' },
                        ]"
                      />
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="12">
                    <a-form-item
                      label="审核员"
                      :name="[index, 'assessorName']"
                      :rules="{ required: true, message: '请选择审核员!' }"
                    >
                      <a-select
                        placeholder="请选择审核员"
                        v-model:value="
                          stateLi.ppmTaskFromList[index].assessorName
                        "
                        showSearch
                        :options="peopleList"
                        :field-names="{ label: 'label', value: 'value' }"
                        :filter-option="
                          (input, option) => {
                            return (
                              option.label
                                .toLowerCase()
                                .indexOf(input.toLowerCase()) >= 0
                            );
                          }
                        "
                      />
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-row class="one-line">
                  <a-col :span="24">
                    <a-form-item
                      label="任务执行人"
                      :name="[index, 'taskParticipantList']"
                      :rules="{ required: true, message: '请选择任务执行人!' }"
                    >
                      <a-select
                        placeholder="请选择任务执行人"
                        v-model:value="
                          stateLi.ppmTaskFromList[index].taskParticipantList
                        "
                        showSearch
                        mode="multiple"
                        :options="peopleList"
                        :field-names="{ label: 'label', value: 'value' }"
                        :filter-option="
                          (input, option) => {
                            return (
                              option.label
                                .toLowerCase()
                                .indexOf(input.toLowerCase()) >= 0
                            );
                          }
                        "
                      />
                    </a-form-item>
                  </a-col>
                  <a-col v-if="taskPeopleList.length > 0">
                    <div
                      style="
                        width: 700px;
                        margin-left: 115px;
                        margin-bottom: 28px;
                      "
                    >
                      <a
                        href="javascript:;"
                        v-for="(item, num) in taskPeopleList"
                        @click="handlerAddPeople(item.value, index)"
                      ><span style="margin: 0 5px">{{ item.value }}</span></a
                      >
                    </div>
                  </a-col>
                </a-row>
                <a-row class="one-line" v-if="!isTemplate">
                  <a-col :span="24">
                    <a-form-item label="验收标准">
                      <a-textarea
                        v-model:value="
                          stateLi.ppmTaskFromList[index].acceptanceCriteria
                        "
                        placeholder="请输入验收标准"
                      />
                    </a-form-item>
                  </a-col>
                </a-row>
                <!-- <a-row class="one-line" v-if="!isTemplate">
<a-col :span="24">
<a-form-item label="甲方工作事项" :name="[index, 'taskRemarks']">
<a-textarea :maxlength="200" v-model:value="stateLi.ppmTaskFromList[index].taskRemarks" placeholder="请输入甲方工作事项" />
</a-form-item>
</a-col>
</a-row> -->
                <a-row class="one-line">
                  <a-col :span="24">
                    <a-form-item label="备注">
                      <a-textarea
                        placeholder="请输入备注"
                        v-model:value="
                          stateLi.ppmTaskFromList[index].description
                        "
                      />
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-row class="one-line" v-if="current.taskId">
                  <a-col :span="24">
                    <a-form-item
                      label="变更原因"
                      :name="[index, 'reasonsChange']"
                      :rules="{ required: true, message: '请填写变更原因!' }"
                    >
                      <a-textarea
                        placeholder="请输入变更原因"
                        v-model:value="
                          stateLi.ppmTaskFromList[index].reasonsChange
                        "
                      />
                    </a-form-item>
                  </a-col>
                </a-row>
              </template>
            </div>
            <a
              v-if="!current.taskId"
              class="del"
              @click="handlerDeleteFormItem(index)"
            >删除</a
            >
          </div>
        </a-form>
        <a-button
          v-if="!current.taskId"
          type="primary"
          ghost
          class="add-btn"
          @click="handlerAddFormItem"
        >
          <plus-outlined />
          添加
        </a-button>
      </a-modal>
      <!--                      模板项目编辑弹窗-->
      <a-modal
        v-model:visible="stateLi.templateEditVisible"
        title="修改任务"
        destroyOnClose
        centered
        width="50%"
        :ok-button-props="{ disabled: btnLoading }"

        @cancel="handlerCancel"
        @ok="beforeSubmit"
      >
        <div class="edit-form">
          <a-form ref="formRef" :model="stateLi.ppmTaskFromList">
            <div
              v-for="(item, index) in stateLi.ppmTaskFromList"
              :key="index"
              class="form-item"
            >
              <div class="form-content">
                <template
                  v-if="stateLi.ppmTaskFromList[index].nodeType === 'TASK'"
                >
                  <a-row class="one-line"></a-row>
                  <a-row>
                    <a-col :span="12">
                      <a-form-item
                        label="预计投入工时"
                        :name="[index, 'workingHours']"
                        :rules="[
                        {
                          required: true,
                          message: '请输入预计投入工时!',
                          trigger: 'blur',
                        },
                        {
                          pattern: /^(0\.5|[1-9](\d*)?(\.5)?(\.0)?)$/,
                          message: '请输入大于0的数字(支持0.5的倍数)',
                          trigger: 'blur',
                        },
                      ]"
                      >
                        <a-input
                          placeholder="请输入工时(支持0.5的数字)"
                          v-model:value="
                          stateLi.ppmTaskFromList[index].workingHours
                        "
                          type="number"
                          suffix="小时"
                        />
                      </a-form-item>
                    </a-col>
                    <a-col :span="12">
                      <a-form-item
                        label="任务起止时间"
                        :name="[index, 'allTime']"
                        :rules="{
                        required: true,
                        message: '请选择任务起止时间!',
                      }"
                      >
                        <a-range-picker
                          :disabled="!canEditTime"
                          v-model:value="stateLi.ppmTaskFromList[index].allTime"
                          valueFormat="YYYY-MM-DD"
                        />
                      </a-form-item>
                    </a-col>
                  </a-row>

                  <a-row class="one-line">
                    <a-col :span="24">
                      <a-form-item
                        label="任务执行人"
                        :name="[index, 'taskParticipantList']"
                        :rules="{ required: true, message: '请选择任务执行人!' }"
                      >
                        <a-select
                          placeholder="请选择任务执行人"
                          v-model:value="
                          stateLi.ppmTaskFromList[index].taskParticipantList
                        "
                          showSearch
                          mode="multiple"
                          :options="peopleList"
                          :field-names="{ label: 'label', value: 'value' }"
                          :filter-option="
                          (input, option) => {
                            return (
                              option.label
                                .toLowerCase()
                                .indexOf(input.toLowerCase()) >= 0
                            );
                          }
                        "
                        />
                      </a-form-item>
                    </a-col>
                    <a-col v-if="taskPeopleList.length > 0">
                      <div
                        style="
                        width: 700px;
                        margin-left: 115px;
                        margin-bottom: 28px;
                      "
                      >
                        <a
                          href="javascript:;"
                          v-for="(item, num) in taskPeopleList"
                          @click="handlerAddPeople(item.value, index)"
                        ><span style="margin: 0 5px">{{ item.value }}</span></a
                        >
                      </div>
                    </a-col>
                  </a-row>

                  <a-row class="one-line">
                    <a-col :span="24">
                      <a-form-item label="备注">
                        <a-textarea
                          placeholder="请输入备注"
                          v-model:value="
                          stateLi.ppmTaskFromList[index].description
                        "
                        />
                      </a-form-item>
                    </a-col>
                  </a-row>
                  <a-row class="one-line" v-if="current.taskId">
                    <a-col :span="24">
                      <a-form-item
                        label="变更原因"
                        :name="[index, 'reasonsChange']"
                        :rules="{ required: true, message: '请填写变更原因!' }"
                      >
                        <a-textarea
                          placeholder="请输入变更原因"
                          v-model:value="
                          stateLi.ppmTaskFromList[index].reasonsChange
                        "
                        />
                      </a-form-item>
                    </a-col>
                  </a-row>
                </template>
              </div>
              <a
                v-if="!current.taskId"
                class="del"
                @click="handlerDeleteFormItem(index)"
              >删除</a
              >
            </div>
          </a-form>
        </div>
      </a-modal>
      <!--                      模板项目编辑弹窗-->
      <a-modal
        v-model:visible="stateLi.closeVisible"
        title="关闭风险"
        destroyOnClose
        centered
        width="40%"
        :ok-button-props="{ disabled: btnLoading }"
        @cancel="stateLi.closeVisible = false"
        @ok="handlerClose"
      >
        <a-form ref="closeFormRef" :model="closeCurrent">
          <div class="form-content">
            <a-row>
              <a-col :span="24">
                <a-form-item
                  label="风险关闭备注"
                  name="riskRemarks"
                  :rules="{ required: true, message: '请输入风险关闭备注!' }"
                >
                  <a-textarea
                    v-model:value="closeCurrent.riskRemarks"
                    :rows="5"
                  />
                </a-form-item>
              </a-col>
            </a-row>
          </div>
        </a-form>
      </a-modal>

      <a-modal
        v-model:visible="stateLi.visibleNotes"
        title="历史备注"
        width="40vw"
        centered
        destroyOnClose
        :footer="null"

        @cancel="stateLi.visibleNotes = false"
      >
        <a-table
          bordered
          rowKey="taskId"
          :customRow="customRow"
          :columns="stateLi.notesColumns"
          :data-source="stateLi.noteData.descriptionDataList"
          :pagination="false"
          :row-class-name="
            (_record, index) => (index % 2 === 1 ? 'table-striped' : null)
          "
        />
      </a-modal>

      <a-modal
        v-model:visible="stateLi.visibleRisk"
        title="风险"
        width="80vw"
        centered
        destroyOnClose
        :footer="null"

        @cancel="stateLi.visibleRisk = false"
      >
        <a-table
          bordered
          rowKey="taskId"
          :customRow="customRow"
          :columns="stateLi.riskColumns"
          :data-source="stateLi.riskList"
          :pagination="false"
          :row-class-name="
            (_record, index) => (index % 2 === 1 ? 'table-striped' : null)
          "
        >
          <template #bodyCell="{ column, record }">
            <template v-if="column.dataIndex === 'operation'">
              <a-button
                type="link"
                :disabled="record.riskState === '关闭'"
                @click="handlerBeforeClose(record)"
              >关闭</a-button
              >
            </template>
          </template>
        </a-table>
      </a-modal>

      <a-modal
        v-model:visible="stateLi.visibleFile"
        title="上传附件"
        destroyOnClose
        centered
        :ok-button-props="{ disabled: btnLoading }"

        @cancel="stateLi.visibleFile = false"
        @ok="handlerUpdateFile"
      >
        <template #footer>
          <a-button key="back" type="primary" @click="downLoadTemplate"
          >下载模板</a-button
          >
          <a-button key="back" @click="stateLi.visibleFile = false"
          >取消</a-button
          >
          <a-button key="submit" type="primary" @click="handlerUpdateFile"
          >确定</a-button
          >
        </template>
        <a-upload
          :file-list="stateLi.fileList"
          :before-upload="handlerUpload"
          @remove="handleRemove"
          accept=".xlsx,.ppt,.pdf,.PDF, image/*, .docx, .rp, .xls"
        >
          <a-button type="primary">
            <upload-outlined />
            上传
          </a-button>
        </a-upload>
        <span>支持格式：image/*,.xlsx,.xls,.docx,.rp,.ppt,.pptx,.pdf</span>
      </a-modal>

      <a-modal
        v-model:visible="stateLi.okVisible"
        title="检查清单列表"
        destroyOnClose
        centered
        width="40%"

        @cancel="stateLi.okVisible = false"
        @ok="handlerOk"
      >
        <div style="border-bottom: 1px solid #d9d9d9; margin-bottom: 10px">
          <div
            v-for="(item, index) in ppmCheckList"
            :key="index"
            class="checkbox-group"
          >
            <div class="label">{{ item.name }}</div>
            <a-checkbox
              v-for="(item2, index2) in item.value"
              :key="index2"
              :checked="ppmCheckedList.includes(item2.checkEntryId)"
              @change="ppmCheckedListChange(item2.checkEntryId)"
            >
              {{ item2.checkEntry }}
            </a-checkbox>
          </div>
        </div>
        <a-upload
          :file-list="stateLi.fileList"
          :before-upload="handlerUpload"
          @remove="handleRemove"
          accept=".xlsx,.ppt,.pdf,.PDF, image/*, .docx, .rp, .xls"
        >
          <a-button type="primary">
            <upload-outlined />
            上传
          </a-button>
        </a-upload>
        <span>支持格式：image/*,.xlsx,.xls,.docx,.rp,.ppt,.pptx,.pdf</span>
      </a-modal>

      <!--                      模板项目-风险预警-->
      <a-modal
        v-model:visible="stateLi.warringVisible"
        title="新增任务风险"
        @ok="handleTemplateRiskOk"
      >
        <a-form :model="stateLi.templateRisk" ref="templateRiskRef">
          <a-row>
            <a-col :span="24">
              <a-form-item
                label="任务名称"
                name="taskName"
                :rules="[
                  {
                    required: true,
                    message: '请输入任务名称',
                    trigger: 'blur',
                  },
                ]"
              >
                <a-input
                  v-model:value="stateLi.templateRisk.taskName"
                  disabled
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="24">
              <a-form-item
                label="风险描述"
                name="riskDescription"
                :rules="[
                  {
                    required: true,
                    message: '请输入风险描述',
                    trigger: 'blur',
                  },
                ]"
              >
                <a-input
                  v-model:value="stateLi.templateRisk.riskDescription"
                ></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="24">
              <a-form-item
                label="解决方案"
                name="solution"
                :rules="[
                  {
                    required: true,
                    message: '请输入解决方案',
                    trigger: 'blur',
                  },
                ]"
              >
                <a-input
                  v-model:value="stateLi.templateRisk.solution"
                ></a-input>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </a-modal>
      <!--                      end模板项目-风险预警-->
      <!-- 新-模板项目检查清单弹出框 -->
      <a-modal
        v-model:visible="stateLi.templateOkVisible"
        title="完成任务"
        destroyOnClose
        centered
        width="40%"

        @cancel="stateLi.templateOkVisible = false"
      >
        <div
          style="border-bottom: 1px solid #d9d9d9; margin-bottom: 10px"
          class="wcrw"
        >
          <a-col :span="24">
            <a-form-item label="实际起止时间">
              <a-range-picker
                show-time
                style="width: 360px"
                v-model:value="jfMbActualFinishTime"
                value-format="YYYY-MM-DD HH:mm:ss"
              />
            </a-form-item>
          </a-col>
          <!-- 完成标准 -->
          <div class="new-check">
            <div class="label">完成标准</div>
          </div>
          <div
            class="checkbox-group"
            v-for="(item, index) in CompletionCheckListCheckList"
            :key="index"
          >
            <a-checkbox v-model:checked="item.selected">
              {{ item.content }}
            </a-checkbox>
          </div>
          <!-- 审核标准 -->
          <div class="new-check" v-if="ppmTemplateCheckList.length > 0">
            <div class="label">审核标准及注意事项</div>
          </div>
          <div
            v-for="(item, index) in ppmTemplateCheckList"
            :key="index"
            class="checkbox-group"
          >
            <div v-html="formatContent(item.content)"></div>
          </div>
          <!-- 审核标准 -->
          <!--                        sop-->
          <div class="new-check" v-if="sopList[0].contentList.length > 0">
            <div class="label">SOP</div>
          </div>
          <div class="checkbox-group">
            <a-checkbox
              v-for="(msg, index) in sopList[0].contentList"
              :key="index"
              v-model:checked="msg.selected"
            >
              {{ msg.msg }}
            </a-checkbox>
          </div>
          <!--                        sop-->
        </div>

        <template #footer>
          <a-button key="back" type="primary" @click="downLoadTemplate"
          >下载模板</a-button
          >
          <a-button key="back" @click="stateLi.templateOkVisible = false"
          >取消</a-button
          >
          <a-button key="back" @click="handleSubmitSop">暂存SOP</a-button>
          <a-button
            key="submit"
            type="primary"
            :loading="templateOkDisabled"
            @click="handlerTemplateOk"
          >
            {{ uploadLoading ? "附件上传中请稍后.." : "提交审批" }}</a-button
          >
        </template>
        <a-spin :spinning="uploadLoading" tip="附件上传中...">
          <a-upload
            :file-list="stateLi.fileList"
            :multiple="true"
            :before-upload="handlerUpload"
            @remove="handleRemove"
            accept=".xlsx,.ppt,.pdf,.PDF, image/*, .docx, .rp, .xls"
          >
            <a-button type="primary">
              <upload-outlined />
              上传
            </a-button>
          </a-upload>
          <span>支持格式：image/*,.xlsx,.xls,.docx,.rp,.ppt,.pptx,.pdf</span>
        </a-spin>
      </a-modal>
      <!-- 模板项目检查清单弹出框 -->
      <!--                  协作分享-->
      <a-modal
        v-model:visible="shareVisible"
        title="协作分享"
        @ok="handleConfirmShare"
        @cancel="handleCancelShare"
        width="1000px"
        centered
      >
        <a-row :gutter="24" style="height: 35px">
          <a-col :span="8">
            <a-form-item label="项目阶段">
              <a-select
                allow-clear
                placeholder="请选择项目阶段"
                v-model:value="shareFilterMilpost"
                showSearch
                :options="stateLi.milepostList"
                :field-names="{ label: 'milepostName', value: 'milepostId' }"
                @focus="getMilepostList"
                @change="handleShareSearch"
                :filter-option="
              (input, option) => {
                return (
                  option.milepostName
                    .toLowerCase()
                    .indexOf(input.toLowerCase()) >= 0
                );
              }
            "
              />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="是否分享">
              <a-select
                placeholder="请选择是否分享"
                v-model:value="shareFilterIsShare"
                :options="[
              {
                label: '是',
                value: true,
              },
              {
                label: '否',
                value: false,
              },
            ]"
                @change="handleShareSearch"
                allow-clear
              />
            </a-form-item>
          </a-col>
        </a-row>
        <div class="table-box">
          <a-table
            :scroll="{ y: '500px' }"
            bordered
            :columns="shareColumns"
            :pagination="false"
            :data-source="shareData"
            row-key="taskId"
            :row-selection="{
          selectedRowKeys: share.selectedRowKeys,
          onChange: onShareSelectChange,
        }"
          >
            <template #bodyCell="{ column, record, text }">
              <template v-if="column.dataIndex === 'opration'">
                <a-checkbox>Checkbox</a-checkbox>
              </template>
            </template>
          </a-table>
        </div>
      </a-modal>
      <!--                  协作分享-->
      <!--审批详情-->
      <a-modal
        @cancel="cancelApprove"
        centered
        v-model:visible="statuState.visible"
        title="审批详情"
        @ok="statusSubmit"
        :body-style="{ minHeight:'500px',maxHeight: '800px', overflowY: 'auto' }"
        :ok-button-props="{loading:approveOkLoading}"
        width="1000px"
      >
        <ApproveStep
          v-if="statuState.visible"
          :taskId="approveTaskId"
          :source="approveSource"
          :type="approveType"
          @cancelModel="cancelApprove"
          @refechData="getTableData"
          ref="approveStepRef"
        />
      </a-modal>

      <!--审批详情-->

      <!--                  sop-->
      <a-modal
        v-model:visible="sopVisible"
        title="SOP"
        :closable="false"
        :footer="null"
        :width="1000"
        :centered="true"
        :destroyOnClose="true"
        :keyboard="false"
        :maskClosable="false"
      >
        <div class="sop-div">
          <div class="one-line-sop">
            <div class="one-left">完成标准</div>
            <div class="one-right">
              <p
                style="color: #262626; margin: 0"
                v-for="(item, index) in handlerGetSpace(sopMsg[0]?.finishStandard)"
                :key="index"
              >
                {{ item }}
              </p>
            </div>
          </div>
          <div class="one-line-sop">
            <div class="one-left">审核标准及注意事项</div>
            <div class="one-right">
              <p
                style="color: #262626; margin: 0"
                v-for="(item, index) in handlerGetSpace(
              sopMsg[0]?.assessorStandard
            )"
                :key="index"
              >
                {{ item }}
              </p>
            </div>
          </div>
          <div class="one-line-sop">
            <div class="one-left">SOP</div>
            <div class="one-right">
              <p class="task-dependency">{{ sopMsg[0]?.taskDependency }}</p>
            </div>
          </div>
          <div class="one-line-sop">
            <div class="one-left">甲方工作事项</div>
            <div class="one-right">
              <p
                style="color: #262626; margin: 0"
                v-for="(item, index) in handlerGetSpace(sopMsg[0]?.taskRemarks)"
                :key="index"
              >
                {{ item }}
              </p>
            </div>
          </div>
          <div class="one-line-sop">
            <div class="one-left">附件模板</div>
            <div class="one-right">
              <a
                v-for="(item, index) in sopMsg[0]?.attachmentTemplateList"
                :key="index"
                href="javascript:"
                @click="attachmentTemplateDownLoad(item)"
                :class="[
              'block',
              index > 2 && !sopMsg[0]?.attachmentShowAll ? 'hide' : '',
            ]"
              >
                {{ item.name }}
              </a>
            </div>
          </div>
          <div class="two-line-sop">
            <div class="two-item">
              <div class="two-left">任务负责人</div>
              <div class="two-right">{{ sopMsg[0]?.taskOwner }}</div>
            </div>
            <div class="two-item">
              <div class="two-left">审核员</div>
              <div class="two-right">{{ sopMsg[0]?.assessorName }}</div>
            </div>
          </div>
        </div>
        <a-button type="primary" class="sop-btn" @click="sopVisible = false"
        >我已知悉</a-button
        >
      </a-modal>
      <!--                  结束sop-->

      <!--                  预览-->
      <a-modal
        v-model:visible="stateF.previewVisible"
        @cancel="stateF.previewVisible=false"
        width="1000px"
        title="图片预览"
        :footer="null"
      >
        <div v-if="stateF.isImagePreview">
          <img :src="stateF.previewImage" alt="附件" style="width: 100%" />
        </div>
        <div v-else>
          <iframe
            :src="stateF.previewFileUrl"
            style="width: 100%; height: 500px"
          ></iframe>
        </div>
      </a-modal>
      <!--                  预览-->
      <!--                  补传附件-->
      <a-modal
        v-model:visible="supVisible"
        title="上传附件"
        destroyOnClose
        centered
        :ok-text="okText"
        :ok-button-props="{ loading: bcfjLoading }"

        @cancel="supVisible = false"
        @ok="handlerSupUpdateFile"
      >
        <a-upload
          :file-list="supFileList"
          :multiple="true"
          :before-upload="handlerSupUpload"
          @remove="handleSupRemove"
          accept=".xlsx,.ppt,.pdf,.PDF, image/*, .docx, .rp, .xls"
        >
          <a-button type="primary">
            <upload-outlined />
            上传
          </a-button>
        </a-upload>
        <span>支持格式：image/*,.xlsx,.xls,.docx,.rp,.ppt,.pptx,.pdf</span>
      </a-modal>
      <!--                  补传附件-->

      <!--                  操作附件-->
      <a-modal
        v-model:visible="showFileVisible"
        title="附件"
        :footer="null"
        @cancel="showFileCancel"
        centered
        :maskClosable="false"
      >
        <div v-for="(item, index) in fileShowList" :key="index" class="file-item">
          <a-dropdown>
        <span
          style="
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            display: block;
          "
          :title="item.name"
        >
          {{ item.name }}
        </span>
            <template #overlay>
              <a-menu>
                <a-menu-item>
                  <a-button
                    style="width: 100%"
                    type="link"
                    size="small"
                    :disabled="!item.type.startsWith('image')"
                    @click="previewAttachment(item)"
                  >预览</a-button
                  >
                </a-menu-item>
                <a-menu-item>
                  <a-button
                    style="width: 100%"
                    type="link"
                    size="small"
                    @click="handlerDownload(item)"
                  >下载</a-button
                  >
                </a-menu-item>
              </a-menu>
            </template>
          </a-dropdown>
        </div>
      </a-modal>
      <!--                  操作附件-->
      <!--                  培训考试-->
      <a-modal
        v-model:visible="pxState.videoVisble"
        width="885px"
        centered
        title="视频文件"
        @cancel="closeVideo"
        destroy-on-close
        :footer="null"
      >
        <div class="video-container">
          <video
            id="video01"
            :src="pxState.videoSrc"
            playsinline
            webkit-playsinline
            preload="auto"
            autoplay
            width="840"
            height="360"
          ></video>
          <!--                    <div class="watermark"></div>-->
        </div>
      </a-modal>
      <a-modal
        v-model:visible="pxState.visible"
        centered
        @cancel="pxState.visible = false"
        :footer="null"
        width="80%"
        :title="pxState.title"
      >
        <div class="px-table-body">
          <div class="px-default-table">
            <a-table
              bordered
              :columns="filteredPxksColumns"
              :data-source="pxState.dataSource"
              @resizeColumn="handleTaskResizeColumn"
              :pagination="false"
              :loading="pxState.pxTableLoading"
              :scroll="{ x: 'max-content', y: 650 }"
            >
              <template #bodyCell="{ column, record, text }">
                <template v-if="column.dataIndex === 'file'">
                  <div class="file-div" v-for="(item, index) in record.fileList">
                    <a-dropdown>
                  <span
                    style="
                      overflow: hidden;
                      white-space: nowrap;
                      text-overflow: ellipsis;
                      display: block;
                    "
                    :title="item.name"
                  >
                    {{ item.name }}
                  </span>
                      <template #overlay>
                        <a-menu>
                          <a-menu-item v-if="isVideo(item.type)">
                            <a-button
                              style="width: 100%"
                              type="link"
                              size="small"
                              @click="showVideo(item.url)"
                            >预览</a-button
                            >
                          </a-menu-item>
                          <a-menu-item>
                            <a-button
                              style="width: 100%"
                              type="link"
                              size="small"
                              @click="handlerDownload(item)"
                            >下载</a-button
                            >
                          </a-menu-item>
                        </a-menu>
                      </template>
                    </a-dropdown>
                  </div>
                </template>
                <template v-if="column.dataIndex === 'videoName'">
                  <template v-if="record.videoList.length > 0">
                    <div
                      v-for="(item, index) in record.videoList"
                      @click="showVideo(item.videoLinks)"
                      class="videolinks"
                    >
                      {{ item.videoName?.trim() }}
                    </div>
                  </template>
                  <!--                                    <div class="video-name" @click="showVideo(record.videoLinks)"> {{ text }}</div>-->
                </template>
                <template v-if="column.dataIndex === 'examLink'">
                  <template v-if="text">
                    <div v-for="(item, index) in handlerGetSpace(text)">
                      <a
                        :key="index"
                        :href="item.trim()"
                        style="display: block"
                        rel="noopener noreferrer"
                        target="_blank"
                      >{{ item?.trim() }}</a
                      >
                    </div>
                  </template>
                </template>
                <template v-if="column.dataIndex === 'description'">
                  <template v-if="text">
                    <div v-for="(item, index) in handlerGetSpace1(text)">
                      {{ item?.trim() }}
                    </div>
                  </template>
                </template>
              </template>
            </a-table>
          </div>
        </div>
      </a-modal>
      <!--                  培训考试-->
      <!--                  任务计划调整-->
      <a-modal
        centered
        v-model:visible="taskWhState.visible"
        width="100%"
        :ok-button-props="{ loading: taskWhState.tipLoading }"
        title="任务计划调整"
        :body-style="{
      paddingTop: '16px',
    }"
        :mask-closable="false"
        :keyboard="false"
        @ok="confirmRwwh"
        @cancel="cancelRwwh"
      >
        <div class="252-new">
          <div class="top-title">
            <a-form-item label="调整类别" style="margin-bottom: 16px">
              <a-radio-group
                v-model:value="taskWhState.radioValue"
                name="radioGroup"
                @change="getWhList"
              >
                <a-radio value="基于SOP">基于SOP</a-radio>
                <a-radio value="灵活调整">灵活调整</a-radio>
              </a-radio-group>
            </a-form-item>
            <a-form-item
              label="开始时间"
              style="margin-bottom: 16px"
              v-if="taskWhState.radioValue === '基于SOP'"
            >
              <a-date-picker
                style="width: 175px"
                valueFormat="YYYY-MM-DD"
                v-model:value="taskWhState.startDate"
                placeholder="选择日期"
                @change="getWhList"
              />
            </a-form-item>
          </div>
          <div class="task-new-table-box">
            <a-table
              :columns="taskNewColumns"
              :dataSource="taskWhState.dataSource"
              :scroll="{ y: 550, x: 'max-content' }"
              :pagination="false"
              :loading="taskWhState.tableLoading"
              bordered
              @resizeColumn="handleResizeNewTaskColumn"
              :showSorterTooltip="false"
              ref="tableRef"
            >
              <template #bodyCell="{ record, text, column, index }">
                <!-- 编辑状态下，展示输入框或选择框 -->
                <!--                                熟料积累条数-->
                <template v-if="column.dataIndex === 'clinkerNumber'">
              <span
                :style="{
                  color: record.level > 0 ? '#3875ff' : '#262626',
                }"
              >{{ text }}</span
              >
                </template>
                <!--                                熟料积累条数-->
                <!--                                计划开始-->
                <!--                                计划开始-->
                <template v-if="column.dataIndex === 'startTime'">
                  <div class="validate-content">
                    <a-date-picker
                      :disabled="taskWhState.radioValue === '基于SOP'"
                      :valueFormat="'YYYY-MM-DD'"
                      style="width: 100%; padding-left: 12px"
                      v-model:value="record.startTime"
                      placeholder="选择日期"
                    />
                    <div class="validate-icon"></div>
                  </div>
                </template>
                <!--                                计划开始-->
                <!--                                实际开始-->
                <template v-if="column.dataIndex === 'actualStarTime'">
                  <div class="validate-content">
                    <a-date-picker
                      :valueFormat="'YYYY-MM-DD'"
                      style="width: 100%; padding-left: 12px"
                      v-model:value="record.actualStarTime"
                      placeholder="选择日期"
                    />
                    <div class="validate-icon"></div>
                  </div>
                </template>
                <!--                                实际开始-->
                <!--                                计划结束-->
                <template v-if="column.dataIndex === 'endTime'">
                  <div class="validate-content">
                    <a-date-picker
                      :disabled="taskWhState.radioValue === '基于SOP'"
                      :valueFormat="'YYYY-MM-DD'"
                      style="width: 100%; padding-left: 12px"
                      v-model:value="record.endTime"
                      placeholder="选择日期"
                    />
                    <div class="validate-icon"></div>
                  </div>
                </template>
                <!--                                计划结束-->
                <!--                                实际结束-->
                <template v-if="column.dataIndex === 'taskFinishTime'">
                  <div class="validate-content">
                    <a-date-picker
                      valueFormat="YYYY-MM-DD hh:mm:ss"
                      show-time
                      style="width: 100%; padding-left: 12px"
                      v-model:value="record.taskFinishTime"
                      placeholder="选择日期"
                    />
                    <div class="validate-icon"></div>
                  </div>
                </template>
                <!--                                实际结束-->
                <!--                                任务负责人-->
                <template v-if="column.dataIndex === 'taskOwner'">
                  <a-select
                    :disabled="record.projectType === '平台项目'"
                    allow-clear
                    show-search
                    style="width: 100%"
                    v-model:value="record.taskOwner"
                    :options="peopleList"
                    placeholder="请选择"
                    :field-names="{ label: 'label', value: 'value' }"
                    :filterOption="
                  (input, option) => {
                    return (
                      option.label.toLowerCase().indexOf(input.toLowerCase()) >=
                      0
                    );
                  }
                "
                    :max-tag-count="2"
                    :getPopupContainer="getPopupContainer"
                  />
                </template>
                <!--                                任务负责人-->
                <!--                                审核员-->
                <template v-if="column.dataIndex === 'assessors'">
                  <a-select
                    allow-clear
                    show-search
                    mode="multiple"
                    style="width: 100%"
                    v-model:value="record.assessors"
                    :options="newPeopleList"
                    placeholder="请选择"
                    :field-names="{ label: 'label', value: 'value' }"
                    :filterOption="
                  (input, option) => {
                    return (
                      option.label.toLowerCase().indexOf(input.toLowerCase()) >=
                      0
                    );
                  }
                "
                    :max-tag-count="2"
                  />
                </template>
                <!--                                审核员-->
                <!--                                执行人-->
                <template v-if="column.dataIndex === 'taskParticipantList'">
                  <a-select
                    allow-clear
                    show-search
                    mode="multiple"
                    style="width: 100%"
                    v-model:value="record.taskParticipantList"
                    :options="newPeopleList"
                    placeholder="请选择"
                    :field-names="{ label: 'label', value: 'label' }"
                    :filterOption="
                  (input, option) => {
                    return (
                      option.label.toLowerCase().indexOf(input.toLowerCase()) >=
                      0
                    );
                  }
                "
                    :max-tag-count="2"
                  />
                </template>
                <!--                                执行人-->
                <!--                              任务状态  -->
                <template v-if="column.dataIndex === 'taskStatus'">
                  <a-select
                    style="width: 100%"
                    allow-clear
                    show-search
                    v-model:value="record.taskStatus"
                    :options="[
                  {
                    label: '未启动',
                    value: '未启动',
                  },
                  {
                    label: '进行中',
                    value: '进行中',
                  },
                  {
                    label: '完成',
                    value: '完成',
                  },
                ]"
                    @change="taskStatusChange(record)"
                    placeholder="请选择"
                    :field-names="{ label: 'label', value: 'value' }"
                    :filterOption="
                  (input, option) => {
                    return (
                      option.label.toLowerCase().indexOf(input.toLowerCase()) >=
                      0
                    );
                  }
                "
                    :getPopupContainer="getPopupContainer"
                  />
                </template>
                <!--                              任务状态  -->
                <!--                              是否隐藏  -->
                <template v-if="column.dataIndex === 'isHidden'">
                  <a-select
                    allow-clear
                    style="width: 100%"
                    placeholder="请选择"
                    :options="[
                  {
                    label: '是',
                    value: 'true',
                  },
                  {
                    label: '否',
                    value: 'false',
                  },
                ]"
                    v-model:value="record.hidden"
                    :getPopupContainer="getPopupContainer"
                  />
                </template>
                <!--                              是否隐藏  -->
                <!--                              关键路径  -->
                <template v-if="column.dataIndex === 'critialPath'">
                  <a-select
                    allow-clear
                    style="width: 100%"
                    placeholder="请选择"
                    :options="[
                  {
                    label: '是',
                    value: '关键路径',
                  },
                  {
                    label: '否',
                    value: '',
                  },
                ]"
                    v-model:value="record.critialPath"
                    :getPopupContainer="getPopupContainer"
                  />
                </template>
                <!--                              关键路径  -->
                <!--任务日志-->
                <template v-if="column.dataIndex === 'taskLog'">
                  <a-input v-model:value="record.taskLog"></a-input>
                </template>
                <!--任务日志-->
                <!--风险点-->
                <template v-if="column.dataIndex === 'riskContent'">
                  <a-input v-model:value="record.riskContent"></a-input>
                </template>
                <!--风险点-->
                <!-- 非编辑状态下，展示原始文本 -->
                <template
                  v-if="['项目阶段', '序号', '任务名称'].includes(column.title)"
                >
                  {{ text }}
                </template>
              </template>
            </a-table>
          </div>
        </div>
      </a-modal>
      <!--                  任务计划维护-->
      <div class="my-page">
        <div class="content-box">
          <div class="right-table">
            <div class="search">
              <div class="search-top">
                <a-form>
                  <a-row style="height: 40px; position: relative">
                    <a-col :span="5">
                      <a-form-item label="计划结束时间" :label-col="{ span: 9 }">
                        <a-date-picker
                          v-model:value="stateLi.filterLi.endTime"
                          valueFormat="YYYY-MM-DD"
                        />
                      </a-form-item>
                    </a-col>
                    <a-col :span="5">
                      <a-form-item label="任务负责人" :label-col="{ span: 9 }">
                        <a-select
                          v-model:value="stateLi.filterLi.taskOwner"
                          allowClear
                          showSearch
                          placeholder="请选择"
                          :options="peopleList"
                          :field-names="{ label: 'label', value: 'value' }"
                          :filter-option="
                          (input, option) => {
                            return (
                              option.label
                                .toLowerCase()
                                .indexOf(input.toLowerCase()) >= 0
                            );
                          }
                        "
                        />
                      </a-form-item>
                    </a-col>

                    <a-col :span="5">
                      <a-form-item label="任务状态" :label-col="{ span: 8 }">
                        <a-select
                          v-model:value="stateLi.filterLi.taskStatusList"
                          mode="multiple"
                          placeholder="请选择"
                          :maxTagCount="1"
                          showArrow="true"
                          allowClear
                          showSearch
                          :options="[
                          { label: '未启动', value: '未启动' },
                          { label: '进行中', value: '进行中' },
                          { label: '完成', value: '完成' },
                          { label: '延期', value: '延期' },
                          { label: '延期完成', value: '延期完成' },
                          { label: '审批中', value: '审批中' },
                          { label: '隐藏', value: '隐藏' },
                        ]"
                        />
                      </a-form-item>
                    </a-col>

                    <a-col :span="4" style="position: relative">
                      <a-form-item>
                        <a-button
                          type="primary"
                          class="mr16 ml10"
                          @click="getTableData"
                        >
                          查询
                        </a-button>

                        <!-- <a-button class="mr16" @click="resetSearch">重置</a-button> -->

                      </a-form-item>
                    </a-col>
                  </a-row>
                </a-form>
              </div>

            </div>



            <div class="table-box">
              <div class="table-top">
                <div class="table-title">任务列表</div>
                <div class="table-top-right">
                  <div v-if="isTemplate" style="position: relative; top: 3px">
                    任务类型：
                    <a-radio-group
                      v-model:value="templateTaskType"
                      @change="radioChange"
                    >
                      <a-radio value="主流程">主流程</a-radio>
                      <a-radio value="数据专项">数据专项</a-radio>
                      <a-radio value="全品种专项">全品种专项</a-radio>
                    </a-radio-group>
                  </div>

                  <a-space>
                    <a-button
                      v-permission="'50001247_vid_skz51dalck'"
                      v-if="isTemplate"
                      type="primary"
                      @click="showTaskWhModal"
                    >
                      任务计划调整</a-button
                    >
                    <a-button
                      v-if="isTemplate"
                      type="primary"
                      ghost
                      @click="handleShareTask"
                    >
                      协作分享
                    </a-button>
                    <a-button
                      v-permission="'50001247_vid_zxcpd6d9bc'"
                      v-if="isTemplate"
                      ghost
                      :loading="downLoading"
                      type="primary"
                      @click="downAllFile"
                    >
                      下载全部附件
                    </a-button>

                  </a-space>
                  <a-space v-if="!isTemplate"><a-button
                    v-permission="'50001247_vid_ejnak1bqqq'"
                    v-if="!isTemplate"
                    type="primary"
                    :disabled="!projectId || !isTask"
                    @click="handlerAdd"
                  >
                    新建
                  </a-button>

                    <a-upload
                      v-permission="'50001247_vid_gqfyjt8979'"
                      v-if="!isTemplate"
                      :before-upload="handlerTaskImport"
                      :file-list="[]"
                      accept=".xlsx, image/*, .docx, .rp, .xls"
                    >
                      <a-tooltip>
                        <template #title>导入</template>
                        <a-button type="primary"
                                  v-permission="'50001247_vid_gqfyjt8979'"
                                  class="export-btn"
                        >
                          导入任务
                        </a-button>
                      </a-tooltip>

                    </a-upload>
                    <a-button
                      v-permission="'50001247_vid_m6vgafslxo'"

                      type="primary"
                      @click="toggleSelection"
                    >{{ showSelection ? "完成" : "关键路径任务" }}</a-button
                    >
                  </a-space>
                </div>
              </div>
              <a-table
                bordered
                :key="tableKey"
                rowKey="taskId"
                :rowSelection="rowTableSelection"
                :loading="stateLi.tableLoading"
                :customRow="customRow"
                :columns="stateLi.columns"
                :data-source="stateLi.dataList"
                :pagination="false"
                :row-class-name="
                (_record, index) => (index % 2 === 1 ? 'table-striped' : null)
              "
                :scroll="{ x: scrollX, y: taskTableHeight }"
                @resizeColumn="handleTaskResizeColumn"
              >
                <template #bodyCell="{ column, record, text }">
                  <!--                                新-任务进度-->
                  <template v-if="column.dataIndex === 'taskSchedule'">
                    <a-progress
                      :percent="record.taskSchedule"
                      status="active"
                    />
                  </template>
                  <!--                                end新-任务进度-->
                  <!-- 新-审核标准字段 -->
                  <template v-if="column.dataIndex === 'assessorStandard'">
                    <a-tooltip
                      @mouseenter="handlerGetStandard(record)"
                      placement="top"
                      :overlayStyle="standardStyle"
                      color="#fff"
                    >
                      <template #title>
                        <p
                          style="color: #262626; margin: 0"
                          v-for="(item, index) in stateLi.standardList"
                          :key="index"
                        >
                          {{ item }}
                        </p>
                      </template>
                      <div
                        style="
                        min-width: 70px;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                        overflow: hidden;
                      "
                      >
                        {{ text }}
                      </div>
                    </a-tooltip>
                  </template>
                  <!-- 审核标准 -->
                  <template
                    v-if="
                    column.dataIndex === 'unclosedRiskNumber' ||
                    column.dataIndex === 'riskNumber'
                  "
                  >
                    <a
                      @click="
                      handlerShowRisks(
                        record,
                        column.dataIndex === 'unclosedRiskNumber'
                          ? '未关闭'
                          : '全部'
                      )
                    "
                    >
                      {{ text }}
                    </a>
                  </template>
                  <!-- 附件模板 -->
                  <template v-if="column.dataIndex === 'attachmentTemplate'">
                    <!-- 预览/下载 -->
                    <!-- 显示前两个附件 -->
                    <div
                      v-for="(item, index) in record.attachmentTemplateList.slice(
                      0,
                      2
                    )"
                      :key="index"
                    >
                      <a-dropdown>
                      <span
                        style="
                          overflow: hidden;
                          white-space: nowrap;
                          text-overflow: ellipsis;
                          display: block;
                        "
                        :title="item.name"
                      >
                        {{ item.name }}
                      </span>
                        <template #overlay>
                          <a-menu>
                            <a-menu-item>
                              <a-button
                                style="width: 100%"
                                type="link"
                                size="small"
                                :disabled="!item.type.startsWith('image')"
                                @click="previewAttachment(item)"
                              >预览</a-button
                              >
                            </a-menu-item>
                            <a-menu-item>
                              <a-button
                                style="width: 100%"
                                type="link"
                                size="small"
                                @click="handlerDownload(item)"
                              >下载</a-button
                              >
                            </a-menu-item>
                          </a-menu>
                        </template>
                      </a-dropdown>
                    </div>

                    <!-- 显示“更多”按钮，当附件超过两个时 -->
                    <div
                      v-if="record.attachmentTemplateList.length > 2"
                      @click="showMore(record.attachmentTemplateList)"
                      style="cursor: pointer; color: #3875ff"
                    >
                      更多
                    </div>
                  </template>
                  <template v-if="column.dataIndex === 'milepostName'">

                    <template v-if="column.dataIndex === 'milepostName'">
                      {{ text }}
                      <div class="milepost-name-opration">
                        <a-button size="small" type="link"
                                  v-permission="'50001247_vid_dtbgvgigrd'"
                                  style="color: #3875ff; margin: 0 6px"
                                  @click="showKspx(record.milepostId, '培训')"
                        >培训</a-button
                        >
                        <a-button size="small" type="link"
                                  v-permission="'50001247_vid_qif3j44thl'"
                                  style="color: #3875ff; margin: 0 6px"
                                  @click="showKspx(record.milepostId, '考试')"
                        >考试</a-button
                        >
                        <a-button size="small" type="link"
                                  v-permission="'50001247_vid_ys09e5q3nr'"
                                  style="color: #3875ff; margin: 0 6px"
                                  @click="faqModelFun(record.milepostName)"
                        >FAQ</a-button
                        >
                      </div>
                    </template>
                  </template>
                  <template v-if="column.dataIndex === 'dependencyTaskName'">
                    {{ record.dependencyTaskIndex }} {{ text }}
                  </template>
                  <!--                                SOP-->
                  <template v-if="column.dataIndex === 'taskDependency'">
                    <a-tooltip
                      placement="top"
                      :overlayStyle="standardStyle"
                      color="#fff"
                    >
                      <template #title>
                        <p
                          v-for="(item, index) in handlerGetSpace(
                          record.taskDependency
                        )"
                          :key="index"
                          style="color: #262626; margin: 0"
                        >
                          {{ item }}
                        </p>
                      </template>
                      <div class="finish-standard">{{ text }}</div>
                    </a-tooltip>
                  </template>
                  <!--                                SOP-->
                  <!-- 完成标准 -->
                  <template v-if="column.dataIndex === 'finishStandard'">
                    <a-tooltip
                      placement="top"
                      :overlayStyle="standardStyle"
                      color="#fff"
                    >
                      <template #title>
                        <p
                          v-for="(item, index) in handlerGetSpace(
                          record.finishStandard
                        )"
                          :key="index"
                          style="color: #262626; margin: 0"
                        >
                          {{ item }}
                        </p>
                      </template>
                      <div class="finish-standard">{{ text }}</div>
                    </a-tooltip>
                  </template>
                  <template v-if="column.dataIndex === 'taskRemarks'">
                    <a-tooltip
                      placement="top"
                      :overlayStyle="standardStyle"
                      color="#fff"
                    >
                      <template #title>
                        <p
                          v-for="(item, index) in handlerGetSpace(
                          record.taskRemarks
                        )"
                          :key="index"
                          style="color: #262626; margin: 0"
                        >
                          {{ item }}
                        </p>
                      </template>
                      <div class="finish-standard">{{ text }}</div>
                    </a-tooltip>
                  </template>
                  <template v-if="column.dataIndex === 'description'">
                    <a-tooltip
                      placement="top"
                      :overlayStyle="standardStyle"
                      color="#fff"
                    >
                      <template #title>
                        <p
                          v-for="(item, index) in handlerGetSpace(
                          record.description
                        )"
                          :key="index"
                          style="color: #262626; margin: 0"
                        >
                          {{ item }}
                        </p>
                      </template>
                      <div class="finish-standard">{{ text }}</div>
                    </a-tooltip>
                  </template>
                  <template v-if="column.dataIndex === 'taskName'">
                    <template v-if="record.collaborate === '协作任务'">
                      <div class="task-collaborate">协作任务</div>

                      <a-tooltip
                        placement="top"
                        :overlayStyle="standardStyle"
                        color="#fff"
                      >
                        <template #title>
                          <p style="color: #262626; margin: 0">{{ text }}</p>
                        </template>
                        <div
                          :class="[
                          'task-name-title',
                          {
                            'task-name-title-right':
                              record.collaborate === '协作任务',
                          },
                        ]"
                        >
                          {{ text }}
                        </div>
                      </a-tooltip>
                    </template>
                    <template v-else>
                      <template v-if="isTemplate">
                        <div class="task-name" >
                          <div class="task-tags">
                            <div v-if="record.critialPath" title="关键路径" class="critical-path"></div>
                            <div v-else-if="record.mark === '初验'" class="task-first">初验</div>
                            <div v-if="record.mark?.includes('里程碑')" class="task-milestone">里程碑</div>
                            <div v-if="record.mark?.includes('终验')" class="task-over">终验</div>
                          </div>

                          <a-tooltip placement="top" :overlayStyle="standardStyle" color="#fff">
                            <template #title>
                              <p style="color: #262626; margin: 0">
                                <span v-if="record.level === 0">{{ record.serialNumberSort }}.{{ record.taskIndex }}</span>
                                {{ record.taskName }}
                              </p>
                            </template>
                            <span class="task-name-title-new">
        <span v-if="record.level === 0">{{ record.serialNumberSort }}.{{ record.taskIndex }}</span>
        {{ record.taskName }}
      </span>
                          </a-tooltip>
                        </div>
                      </template>


                      <div class="task-name" v-else>
                        <div class="task-tags">
                          <div v-if="record.mark === '里程碑'" class="task-milestone">里程碑</div>
                          <div v-else-if="record.mark === '初验'" class="task-first">初验</div>
                          <div v-else-if="record.mark === '终验'" class="task-over">终验</div>
                          <div v-if="record.keynote === '是'" title="关键路径" class="critical-path"></div>
                        </div>
                        <div class="task-content">
                          <a-tooltip placement="top" :overlayStyle="standardStyle" color="#fff">
                            <template #title>
                              <p style="color: #262626; margin: 0">{{ text }}</p>
                            </template>
                            <span class="task-name-title">{{record.taskIndex}}、{{ text }}</span>
                          </a-tooltip>
                        </div>
                      </div>
                    </template>
                  </template>
                  <template v-if="column.dataIndex === 'taskStatus'">
                    <div
                      class="status-tag"
                      title="任务状态"
                      :style="{
                                                    backgroundColor: getStatusColor(record.taskStatus)
                                                }"
                      @click="getTaskStatus(record.taskId,record.verifyMethod,0)"
                    >{{ record.taskStatus || '暂无' }}</div
                    >
                  </template>
                  <template v-if="column.dataIndex === 'attachment'">
                    <!-- 显示前两个附件名 -->
                    <div
                      v-for="(item, index) in record.ppmEnclosureInfoList.slice(
                      0,
                      2
                    )"
                      :key="index"
                    >
                      <a-dropdown>
                      <span
                        style="
                          overflow: hidden;
                          white-space: nowrap;
                          text-overflow: ellipsis;
                          display: block;
                        "
                        :title="item.name"
                      >
                        {{ item.name }}
                      </span>
                        <template #overlay>
                          <a-menu>
                            <a-menu-item>
                              <a-button
                                style="width: 100%"
                                type="link"
                                size="small"
                                :disabled="!item.type.startsWith('image')"
                                @click="previewAttachment(item)"
                              >预览</a-button
                              >
                            </a-menu-item>
                            <a-menu-item>
                              <a-button
                                style="width: 100%"
                                type="link"
                                size="small"
                                @click="handlerDownload(item)"
                              >下载</a-button
                              >
                            </a-menu-item>
                          </a-menu>
                        </template>
                      </a-dropdown>
                    </div>

                    <!-- 显示“更多”按钮，当附件超过两个时 -->
                    <div
                      v-if="record.ppmEnclosureInfoList.length > 2"
                      @click="showMore(record.ppmEnclosureInfoList)"
                      style="cursor: pointer; color: #3875ff"
                    >
                      更多
                    </div>
                  </template>

                  <template v-if="column.dataIndex === 'operation'">
                    <div v-if="record.collaborate !== '协作任务'">
                      <a-space v-if="record.nodeType === 'MENU'">
                        <a-button
                          size="small"
                          type="link"
                          :disabled="record.disabledMenuEditBtn"
                          @click="handlerEdit(record)"
                        >
                          编辑
                        </a-button>
                        <a-popconfirm
                          title="确定要删除吗？"
                          :disabled="record.disabledMenuDelBtn"
                          @confirm="handlerDelete(record)"
                        >
                          <a-button
                            :disabled="record.disabledMenuDelBtn"
                            type="link"
                          >删除</a-button
                          >
                        </a-popconfirm>
                      </a-space>
                      <template v-else>
                        <template v-if="!record.groupTask">
                          <a-button
                            size="small"
                            v-if="record.taskFinishTime && !record.instanceId"
                            type="link"
                            @click="handlerEdit(record, true)"
                          >
                            恢复
                          </a-button>
                          <template v-else>
                            <template v-if="isTemplate">
                              <a-button
                                size="small"
                                v-if="
                                (!record.taskExamStatus ||
                                  record.taskExamStatus === '未通过') &&
                                isTemplate
                              "
                                type="link"
                                @click="handleStart(record)"
                              >
                                开始
                              </a-button>
                              <a-button
                                size="small"
                                v-else
                                type="link"
                                @click="beforeOk(record)"
                              >
                                完成
                              </a-button>
                            </template>
                            <template v-else>
                              <a-button
                                size="small"
                                v-if="!record.examPassTime"
                                type="link"
                                @click="handleOpen(record)"
                              >
                                开始
                              </a-button>
                              <a-button
                                size="small"
                                v-else
                                type="link"
                                @click="beforeOk(record)"
                              >
                                完成
                              </a-button>
                            </template>
                          </template>
                          <a-divider
                            style="margin: 0; border-color: #3875ff"
                            type="vertical"
                          />
                          <a-button
                            size="small"
                            type="link"
                            :disabled="record.disabledEditBtn"
                            @click="handlerEdit(record)"
                          >
                            编辑
                          </a-button>
                          <a-divider
                            style="margin: 0; border-color: #3875ff"
                            type="vertical"
                          />
                          <a-dropdown>
                            <template #overlay>
                              <a-menu @click="handleMenuClick">
                                <a-menu-item key="1" v-if="!isTemplate">
                                  <a-popconfirm
                                    title="确定要删除吗？"
                                    :disabled="record.disabledDelBtn"
                                    @confirm="handlerDelete(record)"
                                  >
                                    <a-button
                                      size="small"
                                      :disabled="record.disabledDelBtn"
                                      type="link"
                                    >删除</a-button
                                    >
                                  </a-popconfirm>
                                </a-menu-item>
                                <a-menu-item key="2"    v-permission="'50001247_vid_u599jfwbpl'">
                                  <a-button
                                    size="small"
                                    type="link"
                                    @click="handlerWarning(record)"

                                  >
                                    预警
                                  </a-button>
                                </a-menu-item>

                                <a-menu-item key="3">
                                  <a-button
                                    size="small"
                                    type="link"
                                    :disabled="record.disabledNoteBtn"
                                    @click="handlerShowNotes(record)"
                                  >
                                    历史备注
                                  </a-button>
                                </a-menu-item>
                                <a-menu-item key="4"
                                             v-permission="'50001247_vid_skee0shw5p'">
                                  <a-button
                                    size="small"
                                    type="link"

                                    @click="handleSup(record)"

                                  >
                                    上传附件
                                  </a-button>
                                </a-menu-item>
                                <a-menu-item
                                  key="5"
                                  v-if="record.hidden === 'false' && isTemplate"
                                  v-permission="'50001247_vid_3o79v7ts3u'"
                                >
                                  <a-button
                                    size="small"
                                    type="link"
                                    @click="handleHiddenTask(record)"

                                  >
                                    任务隐藏
                                  </a-button>
                                </a-menu-item>
                                <a-menu-item
                                  key="6"
                                  v-if="record.hidden === 'true' && isTemplate"
                                >
                                  <a-button
                                    size="small"
                                    type="link"
                                    @click="handleShowTask(record)"
                                  >
                                    任务恢复
                                  </a-button>
                                </a-menu-item>
                              </a-menu>
                            </template>
                            <a-button size="small" type="link">
                              更多
                              <DownOutlined />
                            </a-button>
                          </a-dropdown>
                        </template>
                      </template>
                    </div>
                  </template>
                </template>
              </a-table>
            </div>
          </div>
        </div>


      </div>
      <!-- end vid_nvbvgxjzfj 自定义模板_7gpu8ebdx3 -->
    </a-spin>
  </div>
</template>
<script setup lang="tsx">
import {
  h,
  ref,
  reactive,
  toRaw,
  markRaw,
  watch,
  computed,
  onBeforeMount,
  onMounted,
  onBeforeUnmount,
  onUnmounted,
  onActivated,
  onDeactivated
} from 'vue'
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()
const route = useRoute()
import { get, post, put, del, request, requestWithHeaders } from '@/utils/http/Axios'
import {
  cloneDeep,
  localGet,
  merge,
  getDifferenceArray,
  traversalTreeStructure,
  checkCaseCondition,
  renderStringInTemplate,
  handleBreadcrumbJump,
  throttle,
  permission,
  getComponentParamsValue
} from '@/utils/index'
import { isNullOrEmpty, isEmptyArr, isNullOrUnDef, isContained, isArray, isEmpty, isObject } from '@/utils/is'
import dayjs from 'dayjs'
import { getPagePcChartsDataSourceConvert } from '@/utils/chart'
import { message, notification, Modal } from 'ant-design-vue'
import {
  propertyFormatByNumber,
  propertyFormatByPercentage,
  propertyFormatByDate,
  parseSubFromDataList
} from '@/utils/format'
import colorTheme from '@/design/custom-theme.json'
/*** PUBLISH_EXEGESIS ***
 import UserTableRecords from '@/model/UserTableRecords';
 import { getAppBaseUrl } from '@/utils/index';
 import { sendToken } from "@/hooks/useIframeToken";
 import { useSystemStore } from "@/store/modules/system";
 const systemStore = useSystemStore();
 *** PUBLISH_EXEGESIS ***/

  // 获取传入的流程ID和组件参数
const props = defineProps({
    'processInstanceId': {
      type: [String, Number, Boolean],
      default: undefined
    },
    'useProjectId': {
      type: [String, Number],
      default: '1302'
    }
  })
const immediateWatch = (source, callback) => {
  watch(source, callback, { deep: true, immediate: true })
}

/* -------------------------- 属性定义 -------------------------- */

const setTimeOutList = []
const pageLoading = reactive({
  loading: false,
  tip: undefined
})
const authInfo = localGet('app-user-store')

// 处理校验
const setSubFormName = (parentInfo, name) => {
  return [parentInfo.parents, parentInfo.cycleIndex, name]
}

/* ========================== 属性定义 ========================== */

/* -------------------------- 元素数据引用 -------------------------- */

/* ========================== 元素数据引用 ========================== */

/* -------------------------- 页面数据 -------------------------- */

/* ========================== 页面数据 ========================== */

/* -------------------------- 响应 -------------------------- */

/* ========================== 响应 ========================== */

/* -------------------------- 函数 -------------------------- */

/* ========================== 函数 ========================== */

/* -------------------------- 页面参数 -------------------------- */

const pageParameter_state = reactive({
  'processInstanceId': props.processInstanceId ?? route.query.processInstanceId
})

/* ========================== 页面参数 ========================== */

/* -------------------------- 组件事件处理方法 -------------------------- */

// ---------------------------- 组件数据同步 ----------------------------

// ============================ 组件数据同步 ============================

/* ========================== 组件事件处理方法 ========================== */

/* -------------------------- 生命周期 -------------------------- */
// 用于参数变更后重新执行自定义指令
const queryUpdateFlag = ref(0)
onMounted(() => {})

onUnmounted(() => {
  // 销毁定时器
  setTimeOutList.forEach(({ repeat, timer }) => {
    repeat ? clearInterval(timer) : clearTimeout(timer)
  })
})

/* ========================== 生命周期 ========================== */

/* -------------------------- 数据关联处理 -------------------------- */

/* -------------------------- 表单数据同步 -------------------------- */
/* ========================== 表单数据同步 ========================== */

/* ========================== 数据关联处理 ========================== */

/* -------------------------- 不同组件自定义的处理逻辑 -------------------------- */

/* ========================== 不同组件自定义的处理逻辑 ========================== */

// ================================定制化逻辑========================================
const userInfoStorage = localStorage.getItem('al__USER_INFO');
if (userInfoStorage) {
  try {
    const userInfo = JSON.parse(userInfoStorage);
  } catch (error) {
    console.log(error)
  }
}

const state = reactive({
  tableHeight:400,
  projectDetail:{}
})
const taskTableHeight = ref(520)
const projectId = ref()
watch(
  () => props.useProjectId,
  val => {
    if(!props.useProjectId){
      return
    }
    getProjectDetail()
    projectId.value = props.useProjectId
  },
  { immediate: true }
)
import { nextTick } from 'vue'

function getProjectDetail() {
  get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_project/${props.useProjectId}`)
    .then(async data => {
      state.projectDetail = data.data
      await nextTick()
      checkTaskType()
    })
}
const isTask = ref(true)
watch(
  () => state.projectDetail,
  () => {
    const userInfoStorage = localStorage.getItem('al__USER_INFO')
    const userInfo = JSON.parse(userInfoStorage)
    const userName = userInfo.value.name
    stateLi.userName = state.projectDetail.pmName || ''
    isTemplate.value = !!state.projectDetail.projectTemplate
    setTimeout(() => {
      const detail = state.projectDetail

      // 条件优先级依次判断
      if (detail.delFlag === 3) {
        isTask.value = false
        return
      }

      if (detail.projectStatusOnOrOff === false) {
        isTask.value = false
        return
      }

      if (detail.instanceId !== null) {
        isTask.value = false
        return
      }

      if (detail.pmName !== userName) {
        isTask.value = true
        return
      }

      if (!detail.delFlag) {
        isTask.value = true
        return
      }

      // 默认情况
      isTask.value = true
    }, 500)
  },
  { deep: true }
)
const isLeader = ref(false)
const headerOffset = ref(170)
const calcTableHeight = () => {
  taskTableHeight.value = window.innerHeight - 150 - headerOffset.value
}
onMounted(() => {
  calcTableHeight()
  window.addEventListener('resize', calcTableHeight)
})
onBeforeUnmount(() => {
  window.removeEventListener('resize', calcTableHeight)
})
const stateLi = reactive({
  userName: '',
  tableLoading: false,
  taskList: [],
  taskParticipantList: [],
  milepostList: [],
  filterLi: {
    taskName: '',
    taskParticipantStr: undefined,
    endTime: '',
    taskOwner: undefined,
    taskStatusOnOrOff: 'true',
    taskStatusList: [],
    stateInput: '',
    priorityStr: '',
    milepostId: ''
  },
  columns: [
    {
      title: '项目阶段',
      dataIndex: 'milepostName',
      width: '200px',
      fixed: 'left',
      align: 'left',
      customCell: ({ rowIndex, rowSpan, aa }) => {
        return {
          rowSpan: rowSpan,
          aaa: '44',
          style: {
            fontSize: '16px',
            color: '#262626',
            fontWeight: '600',
            borderTop: aa ? '1px solid #3875ff' : 'none',
          }
        }
      }
    },

    {
      title: '目标',
      dataIndex: 'milepostTarget',

      width: '100px',
      fixed: 'left',
      align: 'left',
    },
    {
      title: '关键路径',
      dataIndex: 'milepostCriticalPath',
      width: '100px',
      fixed: 'left',
      align: 'left',
    },

    {
      title: '任务名称',
      dataIndex: 'taskName',
      width: '300px',
      fixed: 'left',
    },
    {
      title: '任务状态',
      dataIndex: 'taskStatus',
      width: '140px',
      align: 'center',

    },
    {
      title: "任务进度",
      dataIndex: "taskSchedule",
      width: "140px",
      align: "center",
    },
    {
      title: '验收标准',
      dataIndex: 'acceptanceCriteria',
      width: '200px',
      align: 'center',
    },
    {
      title: '附件',
      dataIndex: 'attachment',
      width: '200px',
      align: 'center',
    },
    {
      title: '任务负责人',
      dataIndex: 'taskOwner',
      width: '140px',
      align: 'center',
    },
    {
      title: '审核员',
      dataIndex: 'assessorName',
      width: '140px',
      align: 'center',
    },

    {
      title: '任务执行人',
      dataIndex: 'taskParticipantStr',
      width: '140px',
      align: 'center',
    },
    {
      title: '计划开始',
      dataIndex: 'startTime',
      width: '140px',
      align: 'center',
    },
    {
      title: '实际开始',
      dataIndex: 'actualStarTime',
      width: '140px',
      align: 'center',
    },
    {
      title: '计划完成',
      dataIndex: 'endTime',
      width: '120px',
      align: 'center',
    },
    {
      title: '  实际完成',
      dataIndex: 'taskFinishTime',
      width: '120px',
      align: 'center',
    },
    {
      title: '计划工时(小时)',
      dataIndex: 'workingHours',
      width: '130px',
      align: 'center',
    },
    {
      title: '实际工时(小时)',
      dataIndex: 'actualWorkHours',
      width: '130px',
      align: 'center',
    },
    {
      title: '工时投入状态',
      dataIndex: 'stateInput',
      width: '120px',
      align: 'center',
    },
    {
      title: '优先级',
      dataIndex: 'priorityStr',
      width: '100px',
      align: 'center',
    },
    {
      title: '未关闭风险数量',
      dataIndex: 'unclosedRiskNumber',
      width: '150px',
      align: 'center',
    },
    {
      title: '风险数量',
      dataIndex: 'riskNumber',
      width: '100px',
      align: 'center',
    },
    {
      title: '任务编码',
      dataIndex: '',
      width: '90px',
      align: 'center',
    },


    {
      title: '任务类型',
      dataIndex: 'taskType',
      width: '90px',
      align: 'center',
    },

    {
      title: '依赖任务',
      dataIndex: 'taskDependency',
      width: '90px',
      align: 'center',
    },
    {
      title: '操作',
      dataIndex: 'operation',
      width: '220px',
      align: 'center',
      fixed: 'right',
    }
  ],


  dataList: [],

  spinning: false,
  visible: false,
  ppmTaskFromList: [],
  parentListMap: {},
  visibleNotes: false,
  notesColumns: [
    { title: '备注内容', dataIndex: 'description', align: 'center' },
    { title: '提交人', dataIndex: 'createdBy', align: 'center' },
    { title: '提交时间', dataIndex: 'submissionTime', align: 'center' }
  ],
  noteData: [],
  visibleRisk: false,
  riskList: [],
  riskColumns: [
    { title: '风险描述', dataIndex: 'riskDescription', width: '300px', align: 'center' },
    { title: '解决方案', dataIndex: 'solution', align: 'center' },
    { title: '风险状态', dataIndex: 'riskState', align: 'center' },
    { title: '提交人', dataIndex: 'reportedBy', align: 'center' },
    { title: '提交时间', dataIndex: 'dailyDate', align: 'center' },
    { title: '解决人', dataIndex: 'closeRiskPerson', align: 'center' },
    { title: '风险关闭备注', dataIndex: 'riskRemarks', align: 'center' },
    { title: '操作', dataIndex: 'operation', align: 'center' }
  ],
  closeVisible: false,
  visibleFile: false,
  fileList: [],
  okVisible: false,
  // 任务进度弹窗
  taskScheduleVisible: false,
  taskScheduleModel: {
    id: undefined,
    taskSchedule: undefined,
    status: undefined
  },
  // 风险预警弹窗
  warringVisible: false,
  // 模板项目编辑弹窗
  templateEditVisible: false,
  templateRisk: {
    taskId: undefined,
    taskName: undefined,
    riskDescription: undefined,
    milepostId: undefined,
    projectId: undefined,
    solution: undefined
  },
  // 新-模板检查清单弹窗显示/隐藏
  templateOkVisible: false,
  // 新-模板项目任务审核标准显示/隐藏
  standardVisible: false,
  // 新-审核标准展示的数据
  standardList: [],
  projectManager: true
})
const templateRiskRef = ref(null);
const btnLoading = ref(false)
const taskLeader = JSON.parse(userInfoStorage)
const ppmTaskFromListItem = {
  taskName: undefined,
  milepostId: undefined,
  taskDependency: undefined,
  priority: 'HIGH',
  taskOwner: taskLeader.value.name,
  taskType: '主任务',
  assessorName: taskLeader.value.name,
  startTime: undefined,
  endTime: undefined,
  allTime: [],
  taskParticipantList: [],
  description: undefined,
  workingHours: undefined,
  output: '否',
  parentId: undefined,
  taskIndex: undefined,
  reasonsChange: undefined,
  nodeType: 'TASK',
  // 验收标准
  acceptanceCriteria: undefined,
  // 验收标准
  taskRemarks: undefined
}

function handlerAddFormItem() {
  stateLi.ppmTaskFromList.push({ ...ppmTaskFromListItem })
}

function handleTaskResizeColumn(w, col) {
  col.width = w;
}


const scrollX = stateLi.columns.reduce((pre, cur) => {
  return parseInt(pre.width) + parseInt(cur.width)
}, {})

function formatTableData(data, level = 0) {
  if (!data) {
    return []
  }
  const newData = []
  data.forEach(item => {
    const {
      projectSwitch,
      taskStatusOnOrOff,
      taskStatus,
      operationFlag,
      delFlag,
      attachmentStatus,
      uploadPermission,
      finishPermission,
      projectManager,
      children
    } = item

    item.level = level
    const disabledOkBtn =
      !finishPermission ||
      projectSwitch === 'false' ||
      attachmentStatus === 'false' ||
      operationFlag === 1 ||

      !(!['审批中', '完成', '延期完成'].includes(taskStatus) && delFlag === 0 && !children?.length)

    const disabledMenuEditBtn = !projectManager
    const disabledEditBtn =
      !uploadPermission ||
      projectSwitch === 'false' ||

      taskStatus === '完成' ||
      taskStatus === '延期完成'


    const disabledMenuDelBtn = !projectManager || children?.length > 0

    const disabledDelBtn =
      (!projectManager ||
        projectSwitch === 'false' ||

        taskStatus === '完成' ||
        taskStatus === '延期完成' ||
        taskStatus === '审批中' ||
        delFlag === 2 ||
        (children?.length > 0)) &&
      !(uploadPermission || projectManager);


    const disabledRiskBtn =
      (projectSwitch === 'false' ||

        delFlag === 2 ||
        !projectManager) &&
      !(uploadPermission || projectManager);


    const disabledFileBtn =
      (!projectManager ||
        projectSwitch === 'false' ||

        taskStatus === '完成' ||
        taskStatus === '延期完成' ||
        operationFlag === 1 ||
        taskStatus === '审批中' ||
        delFlag === 2) &&
      !(uploadPermission || projectManager);


    const disabledNoteBtn = false


    const itemChildren = item.children
    item.children = null
    newData.push({
      ...item,
      disabledOkBtn,
      disabledEditBtn,
      disabledDelBtn,
      disabledRiskBtn,
      disabledFileBtn,
      disabledNoteBtn
    })
    if (itemChildren?.length) {
      newData.push(...formatTableData(itemChildren, level + 1))
    }
  })
  return newData
}

function groupData(data) {
  if (!data || !data.length) return [];
  let currentMilepostName = '';
  let currentStageClassify = '';

  return data.map((item, index) => {
    // 1. 计算 milepostName 的 rowSpan
    if (currentMilepostName !== item.milepostName) {
      currentMilepostName = item.milepostName;
      let rowSpan = 0;

      for (let i = index; i < data.length; i++) {
        if (data[i].milepostName === currentMilepostName) {
          rowSpan++;
        } else {
          break;
        }
      }

      item.rowSpan = rowSpan; // 存储 milepostName 的合并行数
      item.isMilepostStart = true; // 标记 milepostName 分组的起始行
    } else {
      item.rowSpan = 0;
      item.isMilepostStart = false;
    }

    // 2. 计算 stageClassify 的 rowSpan
    if (currentStageClassify !== item.stageClassify) {
      currentStageClassify = item.stageClassify;
      let stageClassifyRowSpan = 0;

      for (let i = index; i < data.length; i++) {
        if (data[i].stageClassify === currentStageClassify) {
          stageClassifyRowSpan++;
        } else {
          break;
        }
      }

      item.stageClassifyRowSpan = stageClassifyRowSpan; // 存储 stageClassify 的合并行数
      item.isStageClassifyStart = true; // 标记 stageClassify 分组的起始行
    } else {
      item.stageClassifyRowSpan = 0;
      item.isStageClassifyStart = false;
    }

    item.rowIndex = index; // 可选：记录行索引
    return item;
  });
}
function getTableData() {
  stateLi.dataList = []
  stateLi.tableLoading = true
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/search', {
    ...stateLi.filterLi,
    taskParticipantStr: stateLi.filterLi.taskParticipantStr?.join(','),
    projectId: projectId.value,
    templateTaskType: templateTaskType.value
  })
    .then(({ data }) => {
      stateLi.dataList = groupData(formatTableData(data))
    })
    .finally(() => {
      stateLi.tableLoading = false
    })

}

const resetSearch = () => {
  stateLi.filterLi = {
    taskName: '',
    taskParticipantStr: undefined,
    endTime: '',
    taskOwner: '',
    taskStatusList: [],
    stateInput: '',
    priorityStr: '',
    milepostId: '',
  }
  getTableData()
}

function getTaskList() {
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/list', {
    pageSize: 10000,
    pageNo: 1,
    projectId: projectId.value,
    taskStatusOnOrOff: '全部'
  }).then(({ data }) => {
    stateLi.taskList = data?.dataList?.filter(item => item.nodeType === 'TASK') || []
  })
}

function getTaskParticipantList() {
  post('/base/api/v1/user/search/basic', {
    pageSize: 10000,
    pageNo: 1,
    projectId: projectId.value
  }).then(({ data }) => {
    stateLi.taskParticipantList = data.content
  })
}

function getMilepostList() {
  get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_milepost/${projectId.value}/milepost_name/list`).then(data => {
    stateLi.milepostList = data.data.dataList
  })
}


function init() {
  getTableData()
  getMilepostList()
  getAllJfPeople()
}

const formRef = ref()

const current = ref({})
const closeCurrent = ref({
  dailyItemId: undefined,
  riskRemarks: ''
})
const closeFormRef = ref()

watch(
  () => stateLi.visible,
  () => {
    if (!stateLi.visible) {
      current.value = {}
    }
  }
)

watch(
  () => stateLi.visibleFile,
  () => {
    if (!stateLi.visibleFile) {
      current.value = {}
    }
  }
)

function handlerShowRisks(record, type = '全部') {
  stateLi.visibleRisk = true
  get(`/solution-ppm/api/v2/built-in-system-ppm/daily/${record.taskId}/${type}/queryRiskList`).then(({ dataList }) => {
    stateLi.riskList = dataList
  })
}

// 模板项目附件模板下载
function attachmentTemplateDownLoad(item) {
  pageLoading.loading = true
  const props = { ...item }
  let xhr = new XMLHttpRequest();
  xhr.open('GET', props.url, true);
  xhr.responseType = 'blob';
  xhr.onload = function() {
    if (xhr.status === 200) {
      if (window.navigator.msSaveOrOpenBlob) {
        navigator.msSaveBlob(xhr.response, props.name);
      } else {
        let link = document.createElement('a');
        let body = document.querySelector('body');
        link.href = window.URL.createObjectURL(xhr.response);
        link.download = props.name;
        // fix Firefox
        link.style.display = 'none';
        body.appendChild(link);
        link.click();
        body.removeChild(link);
        window.URL.revokeObjectURL(link.href);
      }
      pageLoading.loading = false
    } else {
      pageLoading.loading = false
    }
  };
  xhr.send();
}

function handlerShowUpdate(record) {
  current.value = record
  stateLi.visibleFile = true
  get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${record.taskId}/queryAttachment`).then(({ data }) => {
    stateLi.fileList = data?.attachment ? JSON.parse(data.attachment) : []
  })
}

function customRow(record, index) {
  return {
    style: {
      cursor: 'pointer'
    }
  }
}



function handlerMilepostIdChange(index, parentId = undefined) {
  const record = stateLi.ppmTaskFromList[index]
  record.parentId = parentId
  get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/parent_tree/${record.milepostId}/${current.value.taskId || 0
  }`).then(({ data }) => {
    stateLi.parentListMap[index] = data
  })
}

function handlerDeleteFormItem(index) {
  stateLi.ppmTaskFromList.splice(index, 1)
  const data = {}
  for (let k in stateLi.parentListMap) {
    if (k < index) {
      data[k] = stateLi.parentListMap[k]
    } else if (k > index) {
      data[k - 1] = stateLi.parentListMap[k]
    }
  }
  stateLi.parentListMap = data
}


function handlerAdd() {
  console.log('点了新建',stateLi.visible);
  if (isTemplate.value) {
    message.info('模板项目不能创建任务')
  } else {
    stateLi.ppmTaskFromList = [{ ...ppmTaskFromListItem }]
    getPopleList()
    stateLi.visible = true
  }
  console.log('点了之后',stateLi.visible);
}

const downLoading = ref(false)

function downAllFile() {
  downLoading.value = true
  post(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/download_file_batch/${projectId.value}`, null, { responseType: 'blob' }).then(res => {
    if (res.type === 'application/octet-stream') {
      downloadZip(res, '全部任务附件.zip');
      downLoading.value = false
    } else {
      message.info('项目没有附件')
      downLoading.value = false
    }
  })
}

const taskPeopleList = ref([])

function getPopleList() {
  post(`/solution-ppm/api/v2/built-in-system-ppm/task/getTopUser/${projectId.value}`).then(data => {
    taskPeopleList.value = data.data.map(item => {
      return {
        label: item,
        value: item
      }
    })
  })
}

function handlerCancel() {
  stateLi.visible = false
  stateLi.templateEditVisible = false;
  ppmTaskFromListItem.taskParticipantList = []
}

function handlerAddPeople(name, index) {
  if (stateLi.ppmTaskFromList[index].taskParticipantList.indexOf(name) !== -1) {
    stateLi.ppmTaskFromList[index].taskParticipantList = stateLi.ppmTaskFromList[index].taskParticipantList.filter(item => item !== name);
  } else {
    stateLi.ppmTaskFromList[index].taskParticipantList.push(name)
  }

}

function handlerSubmit() {
  if (!stateLi.ppmTaskFromList.length) {
    return message.warning('请添加新任务!')
  }
  formRef.value.validate().then(data => {
    btnLoading.value = true
    let params = Object.values(stateLi.ppmTaskFromList).map(item => ({
      ...item,
      startTime: item.allTime[0],
      endTime: item.allTime[1]
    }));
    post(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${projectId.value}/creat`, {
      dataList: params
    })
      .then(({ message: errMsg, code }) => {
        if (code === 200) {
          message.success('操作成功')
          stateLi.visible = false
          ppmTaskFromListItem.taskParticipantList = []
          getTableData()
        } else {
          message.error(errMsg)
        }
      })
      .finally(() => {
        btnLoading.value = false
      })
  })
}

function handlerUpdate() {
  formRef.value.validate().then(() => {
    btnLoading.value = true
    const api = pageType === 'plat' ? put : post
    let newData = {
      ...current.value
    }
    newData.startTime = current.value.allTime[0]
    newData.endTime = current.value.allTime[1]
    api('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/update', { ...newData, projectId: projectId.value })
      .then(({ message: errMsg, code }) => {

        if (code !== 200) {
          message.error(errMsg)
        } else {
          message.success('修改成功')
          stateLi.visible = false
          stateLi.templateEditVisible = false;
          getTableData()
        }

      })
      .finally(() => {
        btnLoading.value = false
      })
  })
}


function handlerRestore() {
  formRef.value.validate().then(() => {
    btnLoading.value = true
    let newData = {
      ...current.value
    }
    newData.startTime = current.value.allTime[0]
    newData.endTime = current.value.allTime[1]
    post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/recovery', {
      ...newData,
      projectId: projectId.value
    })
      .then(({ message: errMsg, code }) => {
        stateLi.templateEditVisible = false
        stateLi.visible = false
        if (code !== 200) {
          message.error(errMsg || '操作失败')
        } else {
          message.success('操作成功')
        }
        getTableData()
      })
      .finally(() => {
        btnLoading.value = false
      })
  })
}

function beforeSubmit() {
  if (current.value.taskId) {
    if (current.value.restore) {
      handlerRestore()
    } else {
      handlerUpdate()
    }
  } else {
    handlerSubmit()
  }
}

function handlerShowNotes(record) {
  stateLi.visibleNotes = true
  post('/solution-ppm/api/v2/built-in-system-ppm/description/queryDescription', {
    sourceId: record.taskId,
    descriptionType: 'TASK'
  }).then(({ data }) => {
    stateLi.noteData = data
  })
}

const editParentList = ref([])

// 是否可以改时间
const canEditTime = ref(false)
function handlerEdit(record, restore = undefined) {
  if (restore) {
    if (!record.recoveryStatus) {
      message.info('只有pmo才可恢复任务')
    } else {
      canEditTime.value = true
      get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${record.taskId}`).then(({ data }) => {
        let oldData = data || {}
        current.value = {
          ...oldData,
          allTime: [oldData.startTime, oldData.endTime],
          parentId: oldData?.parentId ? oldData.parentId : undefined,
          taskId: record.taskId,
          restore
        }
        stateLi.ppmTaskFromList = [current.value]
        handlerMilepostIdChange(0, data?.parentId)
      })
      get(`/solution-ppm/api/v2/built-in-system-ppm/refactoring_task/tree/${record.milepostId}`).then(({ data }) => {
        editParentList.value = data
      })
      getPopleList()
      if (isTemplate.value) {
        canEditTime.value = true
        stateLi.templateEditVisible = true;
      } else {
        stateLi.visible = true;
      }

    }
  } else {
    get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${record.taskId}`).then(({ data }) => {
      let oldData = data || {}
      current.value = {
        ...oldData,
        allTime: [oldData.startTime, oldData.endTime],
        parentId: oldData?.parentId ? oldData.parentId : undefined,
        taskId: record.taskId,
        restore
      }
      stateLi.ppmTaskFromList = [current.value]
      handlerMilepostIdChange(0, data?.parentId)
    })
    get(`/solution-ppm/api/v2/built-in-system-ppm/refactoring_task/tree/${record.milepostId}`).then(({ data }) => {
      editParentList.value = data
    })
    getPopleList()
    if (isTemplate.value) {
      canEditTime.value = false
      stateLi.templateEditVisible = true;
    } else {
      stateLi.visible = true;
    }

  }


}

function handlerDelete(record) {
  if (isTemplate.value === true) {
    message.info('模板项目不能删除任务')
  } else {
    del( '/solution-ppm/api/v2/built-in-system-ppm/delivery_task/approveDeleteTaskByTaskId', {
      data: {
        plName: record.plName,
        taskId: record.taskId
      }
    }).then(({ code, message: errorMsg }) => {
      if (code === 200) {
        message.success('提交成功')
        getTableData()
      } else {
        message.error(errorMsg || '删除失败')
      }
    })
  }

}

// 模板项目-风险预警
function handlerWarning(record) {

  if (record.finishPermission == false || record.operationFlag === 1) {
    message.info('非该任务任务负责人')
  } else {
    if (record.taskFinishTime !== null) {
      message.info('该任务已完成，此功能已关闭')
    } else {
      stateLi.warringVisible = true;
      stateLi.templateRisk.taskName = record.taskName;
      stateLi.templateRisk.riskDescription = record.riskDescription;
      stateLi.templateRisk.solution = record.solution;
      stateLi.templateRisk.taskId = record.taskId;
      stateLi.templateRisk.projectId = record.projectId;
      stateLi.templateRisk.milepostId = record.milepostId;
    }


  }


}

// 模板项目风险保存
function handleTemplateRiskOk() {
  templateRiskRef.value.validate().then(() => {
    const params = {
      taskId: stateLi.templateRisk.taskId,
      projectId: stateLi.templateRisk.projectId,
      milepostId: stateLi.templateRisk.milepostId,
      riskDescription: stateLi.templateRisk.riskDescription,
      solution: stateLi.templateRisk.solution
    };
    post("/solution-ppm/api/v2/built-in-system-ppm/refactoring_task/task_warn", params).then(data => {
      if (data.code === 200) {
        message.success("操作成功");
        stateLi.warringVisible = false;
        getTableData();
      } else {
        message.error(data.message);
      }
    });
  });
}

watch(
  () => stateLi.okVisible,
  () => {
    if (!stateLi.okVisible) {
      current.value = {}
    }
  }
)

const ppmCheckList = ref([])
// 新-审核标准数据
const ppmTemplateCheckList = ref([])
// 新-完成标准数据
const CompletionCheckListCheckList = ref([])
// 注意事项
const ppmCheckedList = ref([])

function beforeOk(record) {
  if(record.verifyMethod==='自动化'){
    statuState.autComplateVisible = true
    autoTask.value = record
    return
  }
  // 交付
  if (record.finishPermission == false || record.operationFlag === 1) {
    message.info('非该任务任务负责人')
  }  else if (record.projectSwitch == 'false') {
    message.info('只有项目开启状态下的任务才能完成')
  } else if ((record.taskStatus === '审批中' || record.taskStatus === '延期完成' || record.taskStatus === '完成') && record.delFlag === 0) {
    message.info(`任务状态为${record.taskStatus}的任务无法进行完成操作`)
  } else if (record.isRiskOrNo == true) {
    message.info('该任务包含风险，请关闭风险后重试')
  } else {
    // 新-判断不同项目点击完成时触发动作
    if (isTemplate.value === true) {
      current.value = record
      // 新-获取审核标准赋值
      get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${current.value.taskId}/standard_info/search`).then(data => {
        ppmTemplateCheckList.value = data.data.assessorStandardList?.map(item => {
          return {
            type: item.type,
            selected: false,
            content: item.content
          }
        }) || []
        sopList.value = data.data.sopList
        if (data.data.finishStandard !== null) {
          CompletionCheckListCheckList.value = data.data.finishStandardList
        } else {
          CompletionCheckListCheckList.value = []
        }
        get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${record.taskId}/queryAttachment`).then(({ data }) => {
          stateLi.fileList = data?.attachment ? JSON.parse(data.attachment) : [];
          stateLi.templateOkVisible = true;
        });

      })
    } else {
      current.value = record
      post('/solution-ppm/api/v2/built-in-system-ppm/checklist//queryPpmMilepostChecklistMap', {
        milepostId: current.value.milepostId
      }).then(({
                 ppmCheckListMap
               }) => {
        const data = []
        let len = 0
        for (let key in ppmCheckListMap) {
          len += ppmCheckListMap[key].length || 0
          data.push({
            name: key,
            value: ppmCheckListMap[key]
          })
        }
        ppmCheckedList.value = []
        ppmCheckList.value = data

        get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${record.taskId}/queryAttachment`).then(({ data }) => {
          stateLi.fileList = data?.attachment ? JSON.parse(data.attachment) : [];
          stateLi.okVisible = true;
        });
      })
    }


  }

}


// 新-模板项目审核标准格式
function handlerGetStandard(data) {
  stateLi.standardList = data.assessorStandard?.split(/[,;；]/);
}

// 新-模板项目审核标准格式
function handlerGetSpace(data) {
  return data?.split(/[,;；]/);
}

// 新-模板项目检查清单保存按钮
function standClose() {
  stateLi.standardVisible = false
  stateLi.standardList = []
}

function handlerOk() {

  if (current.value.output === '是' && stateLi.fileList.length < 1) {
    message.info('请上传附件')
  } else {
    stateLi.btnLoading = true;
    post("/solution-ppm/api/v2/built-in-system-ppm/delivery_task/attachmentUploading", {
      ppmEnclosureInfoList: stateLi.fileList,
      taskId: current.value.taskId
    }).then(data => {
      if (data.code === 200) {
        post("/solution-ppm/api/v2/built-in-system-ppm/delivery_task/taskCompletionApprovalFlow", {
          plName: current.value.plName,
          taskId: current.value.taskId
        }).then(data => {
          if (data.code === 200) {
            stateLi.btnLoading = false;
            stateLi.okVisible = false;
            getTableData();
            message.success("操作成功");
          } else {
            message.error('提交失败')
          }
        })
      } else {
        message.error('上传附件失败')
      }
    })
  }


}


function handlerBeforeClose(record) {

  if (record.disablePermission === 'false') {
    message.info('暂无权限')
  } else {
    closeCurrent.value = {
      dailyItemId: record.dailyItemId,
      riskRemarks: '',
      taskId: record.taskId
    }
    stateLi.closeVisible = true
  }

}

function handlerClose() {
  closeFormRef.value.validate().then(() => {
    btnLoading.value = true
    post('/solution-ppm/api/v2/built-in-system-ppm/daily/updateRiskState', closeCurrent.value)
      .then(({ code, message: errMsg }) => {
        if (code === 200) {
          stateLi.closeVisible = false
          handlerShowRisks(closeCurrent.value)
          message.success('操作成功')
        } else {
          message.warning(errMsg || '操作失败')
        }
      })
      .finally(() => {
        btnLoading.value = false
      })
  })
}

const uploadLoading = ref(false)

function handlerUpload(file) {
  uploadLoading.value = true
  templateOkDisabled.value = true
  const data = new FormData()
  data.append('file', file)
  post('/file-storage/api/v1/file/upload', data).then(({ data: { fullUrl } }) => {
    if (data) {
      stateLi.fileList = [
        ...stateLi.fileList,
        {
          uid: file.uid,
          lastModified: file.lastModified,
          name: file.name,
          size: file.size,
          type: file.type,
          status: 'done',
          url: fullUrl
        }
      ]
    }
  }).finally(() => {
    uploadLoading.value = false
    templateOkDisabled.value = false
  })
  return false
}

function handleRemove(file) {
  stateLi.fileList = stateLi.fileList.filter(item => item.uid !== file.uid)
}

function handlerUpdateFile() {
  stateLi.btnLoading = true
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/attachmentUploading', {
    ppmEnclosureInfoList: stateLi.fileList,
    taskId: current.value.taskId
  }).then(() => {
    stateLi.btnLoading = false
    stateLi.visibleFile = false
    message.success('操作成功')
    getTableData()
  })
}

// 任务下载全部模板
function downLoadTemplate() {
  if (current.value.attachmentTemplateList.length < 1) {
    message.info('任务没有附件')
  } else {
    post(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/download_template/${current.value.taskId}`, null, { responseType: 'arraybuffer' }).then(res => {
      downloadZip(res, '任务附件模板.zip');
    })
  }


}

function downloadZip(response, name) {
  const blob = new Blob([response], { type: 'application/zip;charset=utf-8' });
  const downloadElement = document.createElement('a');
  const href = window.URL.createObjectURL(blob);
  downloadElement.href = href;
  downloadElement.download = name; // 下载后文件名
  document.body.appendChild(downloadElement);
  downloadElement.click();
  document.body.removeChild(downloadElement);
  window.URL.revokeObjectURL(href);
  return href;
}

function ppmCheckedListChange(value) {
  if (ppmCheckedList.value.includes(value)) {
    ppmCheckedList.value = ppmCheckedList.value.filter(item => item !== value)
  } else {
    ppmCheckedList.value.push(value)
  }
}

const jfMbActualFinishTime = ref()

// 新-新模板项目检查清单确认事件
function handlerTemplateOk() {
  if (!checkAllSelected(CompletionCheckListCheckList.value)) {
    message.info('请确认完成标准及SOP全部已实现');
  } else if (stateLi.fileList.length < 1) {
    message.info('请上传附件');
  } else if (!checkAllSelected(sopList.value[0].contentList)) {
    message.info('请确认完成标准及SOP全部已实现');
  } else {
    handlerCheckOk();
  }
}

const templateOkDisabled = ref(false)

function handlerCheckOk() {
  templateOkDisabled.value = true
  const params = {
    form: [],
    sopList: sopList.value,
    taskId: current.value.taskId,
    actualStartTime: jfMbActualFinishTime.value
  }
  params.form = [...CompletionCheckListCheckList.value, ...ppmTemplateCheckList.value]
  post("/solution-ppm/api/v2/built-in-system-ppm/delivery_task/attachmentUploading", {
    ppmEnclosureInfoList: stateLi.fileList,
    taskId: current.value.taskId
  }).then(data => {
    if (data.code === 200) {
      post(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${current.value.taskId}/standard_info/submit`, params).then(data => {
        if (data.code === 200) {
          templateOkDisabled.value = false;
          stateLi.templateOkVisible = false;
          message.success("操作成功");
          getTableData();
        } else {
          message.error('提交失败')
          templateOkDisabled.value = false
        }
      })
    } else {
      templateOkDisabled.value = false
      message.error('附件上传失败')
    }
  })

}



function handlerDownload({ url, name }) {

  function downBlob(blob) {
    const downloadElement = document.createElement('a')
    const href = window.URL.createObjectURL(blob) // 创建下载的链接
    downloadElement.href = href
    downloadElement.download = name // 下载后文件名
    document.body.appendChild(downloadElement)
    downloadElement.click() // 点击下载
    document.body.removeChild(downloadElement) // 下载完成移除元素
    window.URL.revokeObjectURL(href)
  }

  pageLoading.loading = true
  pxState.pxTableLoading = true
  const data = new FormData()
  data.append('path', url)
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/downloadFile', data, {
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  }).then(blob => {
    downBlob(blob)
  }).finally(() => {
    pageLoading.loading = false
    pxState.pxTableLoading = false
  })
}

// TODO:任务导出方法
function downloadExcel(response, name) {
  const blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' });
  const downloadElement = document.createElement('a');
  const href = window.URL.createObjectURL(blob);// 创建下载的链接
  downloadElement.href = href;
  downloadElement.download = name; // 下载后文件名
  document.body.appendChild(downloadElement);
  downloadElement.click(); // 点击下载
  document.body.removeChild(downloadElement); // 下载完成移除元素
  window.URL.revokeObjectURL(href);
  return href;
}

function handlerTaskExport() {
  //可能会变
  post(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/export/${projectId.value}`, null, { responseType: 'arraybuffer', }).then(res => {
    downloadExcel(res, '任务.xlsx')
  })
}

// 任务导出方法
// TODO:任务导入方法
function handlerTaskImport(file) {
  if (!projectId) {
    message.info('请选择项目')
  } else if (!stateLi.projectManager) {
    message.info('只有项目经理可以导入任务')
  } else if (isTemplate.value === true) {
    message.info('模板项目无法导入任务')
  } else {
    //可能会变
    const data = new FormData()
    data.append('file', file)
    post(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/upload/${projectId.value}`, data).then(({
                                                                                                           message: errorMsg,
                                                                                                           code
                                                                                                         }) => {
      if (code !== 200) {
        message.error(errorMsg)
      } else {
        message.success('导入成功')
      }
      // 成功后刷新列表
      getTableData()
    })
    return false
  }

}

// 任务导入方法

function validateEndTime({ startTime, endTime }) {
  if (startTime && endTime) {
    const time1 = new Date(startTime).getTime()
    const time2 = new Date(endTime).getTime()
    if (time1 > time2) {
      return Promise.reject('任务结束日期必须大于等于任务开始日期')
    }
  }
  return Promise.resolve()
}

const statuState = reactive({
  visible: false,
  list: [],
  autComplateVisible:false,
  repParams:undefined,
  radioValue:'默认参数'
})

function getTaskStatus(id, type) {
  console.log(type,'type');
  approveTaskId.value = id
  approveType.value = type
  statuState.visible = true
}


const getIconStatus = status => {
  if (status === 'finish') {
    return 'finish'
  } else if (status === 'process') {
    return 'process'
  } else {
    return 'error'
  }
}


const shareVisible = ref(false)
const shareFilterMilpost = ref('')
const shareFilterIsShare = ref('')
const shareColumns = [
  {
    title: '项目阶段',
    dataIndex: 'milepostName',
    resizable: true,
    ellipsis: true,
  },
  {
    title: '任务名称',
    dataIndex: 'taskName',
    ellipsis: true,
    resizable: true
  }
]
const share = reactive({
  selectedRowKeys: [],
  allSelectedRowKeys: []
})
// 当用户选择或取消勾选时触发
const onShareSelectChange = (selectedRowKeys) => {
  // 更新当前展示的数据选中项
  share.selectedRowKeys = selectedRowKeys;

  // 如果取消了某个选中的数据，将它从 allSelectedRowKeys 中移除
  share.allSelectedRowKeys = [...new Set([
    ...share.allSelectedRowKeys.filter(id => selectedRowKeys.includes(id) || !shareData.value.some(item => item.taskId === id)),
    ...selectedRowKeys
  ])];
};
const shareData = ref([])

function handleConfirmShare() {
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/share_submit', {
    projectId: projectId.value,
    taskIdList: [...share.selectedRowKeys]
  }).then(data => {
    message.success('操作成功')
    shareVisible.value = false
    shareFilterIsShare.value = null
  })
}

function handleCancelShare() {
  shareVisible.value = false
}

// 获取数据后处理反显
function handleShareTask() {
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/share_search', {
    "share": '',
    "milepostId": shareFilterMilpost.value,
    projectId: projectId.value
  }).then(({ data }) => {
    const result = data.filter(item => item.share).map(item => item.taskId);
    shareData.value = data;

    // 合并反显的数据和之前选中的数据，确保不丢失
    share.selectedRowKeys = share.allSelectedRowKeys.filter(id => data.some(item => item.taskId === id));
    share.allSelectedRowKeys = [...new Set([...share.allSelectedRowKeys, ...result])];
    shareVisible.value = true;
  });
}

function handleShareSearch() {
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/share_search', {
    share: shareFilterIsShare.value,
    "milepostId": shareFilterMilpost.value,
    projectId: projectId.value
  }).then(({ data }) => {
    const result = data.filter(item => item.share).map(item => item.taskId);
    shareData.value = data;

    // 同步筛选后的数据，并确保不会影响之前的数据
    share.selectedRowKeys = share.allSelectedRowKeys.filter(id => data.some(item => item.taskId === id));
    share.allSelectedRowKeys = [...new Set([...share.allSelectedRowKeys, ...result])];
  });
}

const fileShowList = ref([])
const showFileVisible = ref(false)

function showMore(data) {
  fileShowList.value = data
  showFileVisible.value = true
}

function showFileCancel() {
  fileShowList.value = []
  showFileVisible.value = false
}

// 任务类型
const templateTaskType = ref('主流程')

function radioChange() {
  getTableData()
}

function checkTaskType() {
  if (isTemplate.value) {
    templateTaskType.value = '主流程'
  } else {
    templateTaskType.value = undefined
  }
  init()
}

// 任务优化
// 审批详情
import ApproveStep from './Page3000001149.vue'
const approveTaskId = ref()
const approveType = ref()
const approveSource = '0'
function cancelApprove() {
  statuState.visible = false
}
const approveStepRef = ref(null)
const approveOkLoading = ref(false)
async function statusSubmit() {
  approveOkLoading.value = true
  try {
    await approveStepRef.value?.submitWord()
    // 提交成功，父组件可以额外处理逻辑
  } catch (e) {
    // 提交失败，不影响 loading 恢复
    console.error(e)
  } finally {
    approveOkLoading.value = false
  }
}
const isTemplate = ref(false)
// 加减分详情弹窗

const tableKey = ref(0);
watch(
  () => isTemplate.value,
  () => {
    stateLi.dataList = [];
    if (isTemplate.value === true) {
      stateLi.columns = [
        {
          title: '项目阶段',
          dataIndex: 'stageClassify',
          ellipsis: true,
          align: 'left',
          fixed: 'left',
          width: '200px',
          customCell: ({ rowIndex, stageClassifyRowSpan, aa }) => {
            return {
              rowSpan: stageClassifyRowSpan,
              aaa: '44',
              style: {
                fontSize: '16px',
                color: '#262626',
                fontWeight: '600',
                borderTop: aa ? '1px solid #3875ff' : 'none',
              }
            }
          }

        },

        {
          title: '里程碑阶段',
          dataIndex: 'milepostName',
          resizable: true,
          ellipsis: true,
          width: '160px',
          fixed: 'left',
          align: 'left',
          customCell: ({ rowIndex, rowSpan, aa }) => {
            return {
              rowSpan: rowSpan,
              aaa: '44',
              style: {
                fontSize: '16px',
                color: '#262626',
                fontWeight: '600',
                borderTop: aa ? '1px solid #3875ff' : 'none',
              }
            }
          }
        },
        {
          title: '目标',
          dataIndex: 'milepostTarget',
          resizable: true,
          ellipsis: true,
          width: '160px',
          fixed: 'left',
          align: 'left',
          customCell: ({ rowIndex, rowSpan, aa }) => {
            return {
              rowSpan: rowSpan,
              aaa: '44',
              style: {
                borderTop: aa ? '1px solid #3875ff' : 'none',
              }
            }
          }
        },
        {
          title: '关键路径',
          dataIndex: 'milepostCriticalPath',
          resizable: true,
          ellipsis: true,
          width: '120px',
          align: 'left',
          customCell: ({ rowIndex, rowSpan, aa }) => {
            return {
              rowSpan: rowSpan,
              aaa: '44',
              style: {
                borderTop: aa ? '1px solid #3875ff' : 'none',
              }
            }
          }
        },
        {
          title: '甲方角色',
          dataIndex: 'milepostFirstPartyMainRole',
          ellipsis: true,
          align: 'left',
          width: '120px',

          customCell: item => {
            const { rowIndex, rowSpan ,aa} = item
            return {
              rowSpan: rowSpan,
              style: {
                borderTop: aa ? '1px solid #3875ff' : 'none'
              }
            }
          }
        },
        {
          title: '甲方责任及配合内容',
          dataIndex: 'milepostFirstPartyRespAndCoopMatters',
          ellipsis: true,
          align: 'left',
          width: '160px',

          customCell: item => {
            const { rowIndex, rowSpan ,aa} = item
            return {
              rowSpan: rowSpan,
              style: {
                borderTop: aa ? '1px solid #3875ff' : 'none'
              }
            }
          }
        },
        {
          title: '任务名称',
          dataIndex: 'taskName',
          ellipsis: true,
          resizable: true,
          width: '300px',
          align: 'left',
          customCell: ({ level, nodeType, aa, rowIndex, groupTask }) => {
            return {
              style: {
                color: `${groupTask ? '#3875ff' : ''}`,
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none',
              }
            }
          }
        },
        {
          title: '任务状态',
          dataIndex: 'taskStatus',
          resizable: true,
          ellipsis: false,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        }, {
          title: "任务进度",
          dataIndex: "taskSchedule",
          resizable: true,
          ellipsis: false,
          width: "140px",
          align: "center",
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? "1px solid #3875ff" : "none"
              }
            };
          }
        },

        {
          title: '完成标准',
          dataIndex: 'finishStandard',
          resizable: true,
          ellipsis: true,
          width: '250px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        // 新-模板项目审核标准字段
        {
          title: '审核标准及注意事项',
          dataIndex: 'assessorStandard',
          resizable: true,
          ellipsis: true,
          width: '250px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },

        {
          title: 'SOP',
          dataIndex: 'taskDependency',
          resizable: true,
          ellipsis: true,
          width: '250px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '附件模板',
          dataIndex: 'attachmentTemplate',
          resizable: true,
          ellipsis: true,
          width: '200px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '附件',
          dataIndex: 'attachment',
          resizable: true,
          ellipsis: true,
          width: '200px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '依赖任务',
          dataIndex: 'dependencyTaskName',
          resizable: true,
          ellipsis: true,
          width: '250px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '任务负责人',
          dataIndex: 'taskOwner',
          resizable: true,
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '审核员',
          dataIndex: 'assessorName',
          resizable: true,
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },

        {
          title: '任务执行人',
          resizable: true,
          dataIndex: 'taskParticipantStr',
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '任务角色',
          dataIndex: 'taskRole',
          ellipsis: true,
          align: 'center',
          width: '160px',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            }
          }
        },
        {
          title: '计划开始',
          dataIndex: 'startTime',
          resizable: true,
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '预计开始',
          dataIndex: 'estimatedStartTime',
          resizable: true,
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '实际开始',
          dataIndex: 'actualStarTime',
          resizable: true,
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '计划完成',
          dataIndex: 'endTime',
          ellipsis: true,
          width: '120px',
          resizable: true,
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '预计完成',
          dataIndex: 'estimatedEndTime',
          ellipsis: true,
          width: '120px',
          resizable: true,
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '    实际完成',
          dataIndex: 'taskFinishTime',
          ellipsis: true,
          resizable: true,
          width: '120px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '计划工时(小时)',
          dataIndex: 'workingHours',
          resizable: true,
          ellipsis: true,
          width: '130px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '实际工时(小时)',
          dataIndex: 'actualWorkHours',
          resizable: true,
          ellipsis: true,
          width: '130px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '工时投入状态',
          dataIndex: 'stateInput',
          resizable: true,
          ellipsis: true,
          width: '120px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '优先级',
          dataIndex: 'priorityStr',
          resizable: true,
          ellipsis: true,
          width: '100px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '未关闭风险数量',
          dataIndex: 'unclosedRiskNumber',
          resizable: true,
          ellipsis: true,
          width: '150px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '风险数量',
          dataIndex: 'riskNumber',
          resizable: true,
          ellipsis: true,
          width: '100px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '操作',
          dataIndex: 'operation',
          width: '220px',
          align: 'center',
          fixed: 'right',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        }
      ]
    } else {
      stateLi.columns = [
        {
          title: '项目阶段',
          dataIndex: 'milepostName',
          resizable: true,
          ellipsis: true,
          width: '200px',
          fixed: 'left',
          align: 'left',
          customCell: ({ rowIndex, rowSpan, aa }) => {
            return {
              rowSpan: rowSpan,
              aaa: '44',
              style: {
                fontSize: '16px',
                color: '#262626',
                fontWeight: '600',
                borderTop: aa ? '1px solid #3875ff' : 'none',
              }
            }
          }
        },

        {
          title: '任务名称',
          dataIndex: 'taskName',
          ellipsis: true,
          resizable: true,
          width: '300px',
          fixed: 'left',
          align: 'left',
          customCell: ({ level, nodeType, aa, rowIndex }) => {
            return {
              style: {
                paddingLeft: `${(level + 1) * 20}px`,
                color: `${nodeType === 'MENU' ? '#3875ff' : ''}`,
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            }
          }
        },
        {
          title: '任务状态',
          dataIndex: 'taskStatus',
          resizable: true,
          ellipsis: false,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: "任务进度",
          dataIndex: "taskSchedule",
          resizable: true,
          ellipsis: false,
          width: "140px",
          align: "center",
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? "1px solid #3875ff" : "none"
              }
            };
          }
        },
        {
          title: '验收标准',
          dataIndex: 'acceptanceCriteria',
          resizable: true,
          ellipsis: true,
          width: '200px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '附件',
          dataIndex: 'attachment',
          resizable: true,
          ellipsis: true,
          width: '200px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '任务负责人',
          dataIndex: 'taskOwner',
          resizable: true,
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '审核员',
          dataIndex: 'assessorName',
          resizable: true,
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },

        {
          title: '任务执行人',
          resizable: true,
          dataIndex: 'taskParticipantStr',
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '计划开始',
          dataIndex: 'startTime',
          resizable: true,
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '实际开始',
          dataIndex: 'actualStarTime',
          resizable: true,
          ellipsis: true,
          width: '140px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '计划完成',
          dataIndex: 'endTime',
          ellipsis: true,
          width: '120px',
          resizable: true,
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '    实际完成',
          dataIndex: 'taskFinishTime',
          ellipsis: true,
          resizable: true,
          width: '120px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '计划工时(小时)',
          dataIndex: 'workingHours',
          resizable: true,
          ellipsis: true,
          width: '130px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '实际工时(小时)',
          dataIndex: 'actualWorkHours',
          resizable: true,
          ellipsis: true,
          width: '130px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '工时投入状态',
          dataIndex: 'stateInput',
          resizable: true,
          ellipsis: true,
          width: '120px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '优先级',
          dataIndex: 'priorityStr',
          resizable: true,
          ellipsis: true,
          width: '100px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '未关闭风险数量',
          dataIndex: 'unclosedRiskNumber',
          resizable: true,
          ellipsis: true,
          width: '150px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '风险数量',
          dataIndex: 'riskNumber',
          resizable: true,
          ellipsis: true,
          width: '100px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '任务编码',
          dataIndex: '',
          ellipsis: true,
          resizable: true,
          width: '90px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },


        {
          title: '任务类型',
          dataIndex: 'taskType',
          resizable: true,
          ellipsis: true,
          width: '90px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },

        {
          title: '依赖任务',
          dataIndex: 'taskDependency',
          resizable: true,
          ellipsis: true,
          width: '90px',
          align: 'center',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        },
        {
          title: '操作',
          dataIndex: 'operation',
          width: '220px',
          align: 'center',
          fixed: 'right',
          customCell: ({ rowSpan, rowIndex, aa }) => {
            return {
              style: {
                borderTop: aa && rowIndex ? '1px solid #3875ff' : 'none'
              }
            };
          }
        }


      ]
    }
    tableKey.value += 1;
  }, {
    deep: true
  }
)

// tooltip样式
const standardStyle = {
  maxWidth: '500px',
}

// 图片预览

const stateF = reactive({
  previewVisible: false,
  previewImage: '',
  previewFileUrl: '',
  isImagePreview: false,
})

function previewAttachment(item) {
  // 检查附件类型
  if (item.type.startsWith('image')) {
    stateF.isImagePreview = true;
    stateF.previewImage = item.url; // 设置预览图片的URL
    stateF.previewVisible = true; // 显示模态框
  } else {
    // stateF.isImagePreview = false;
    // // 如果是其他类型的文件，直接在模态框中显示
    // stateF.previewFileUrl = item.url; // 设置预览文件的URL
    message.info('目前仅支持图片预览')
  }

}

// 补传附件
const supVisible = ref(false)
const supRecord = ref({})
const supFileList = ref([])
const bcfjLoading = ref(false)

function handlerSupUpdateFile() {
  bcfjLoading.value = true;
  post("/solution-ppm/api/v2/built-in-system-ppm/delivery_task/attachmentUploading", {
    ppmEnclosureInfoList: supFileList.value,
    taskId: supRecord.value.taskId
  }).then(data => {
    if (data.code === 200) {
      bcfjLoading.value = false
      supVisible.value = false
      getTableData();
      message.success(data.message);
    } else {
      bcfjLoading.value = false
      message.error(data.message)
    }
  })

}

// 补传附件loading
const bcFileLoading = ref(false)
const okText = computed(() => (bcFileLoading.value ? '附件上传中请稍后..' : '确定'))
function handlerSupUpload(file) {
  bcFileLoading.value = true
  bcfjLoading.value = true
  const data = new FormData()
  data.append('file', file)
  post('/file-storage/api/v1/file/upload', data).then(({ data: { fullUrl } }) => {
    if (data) {
      supFileList.value = [
        ...supFileList.value,
        {
          uid: file.uid,
          lastModified: file.lastModified,
          name: file.name,
          size: file.size,
          type: file.type,
          status: 'done',
          url: fullUrl
        }
      ]
    }
  }).finally(()=>{
    bcFileLoading.value = false
    bcfjLoading.value = false
  })
  return false
}

function handleSupRemove(file) {
  supFileList.value = supFileList.value.filter(item => item.uid !== file.uid)
}

function handleSup(record) {
  if (record.finishPermission === false) {
    message.info('非任务负责人无权限')
  } else {
    supRecord.value = record
    supFileList.value = record.ppmEnclosureInfoList
    supVisible.value = true
  }
}



// 任务显示隐藏
const isTaskShow = reactive({
  taskShowVisible: false,
  showTitle: '任务隐藏',
  currentTask: {},
  isShow: false
})
const showOrHideTask = () => {
  if (isTaskShow.isShow) {
    put(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${isTaskShow.currentTask.taskId}/status/CANCEL_HIDDEN`).then(data => {
      if (data.code === 200) {
        message.success('任务恢复成功')
        isTaskShow.taskShowVisible = false
        getTableData()
      } else {
        message.error(data.message)
      }
    })
  } else {
    put(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${isTaskShow.currentTask.taskId}/status/HIDDEN`).then(data => {
      if (data.code === 200) {
        message.success('任务隐藏成功')
        isTaskShow.taskShowVisible = false
        getTableData()
      } else {
        message.error(data.message)
      }
    })
  }
}

function batchDelayCancel() {
  batchDelay.delayVisible = false
  batchDelayRef.value.clearValidate()
  batchDelay.model.count = undefined
}

function taskShowCancel() {
  isTaskShow.taskShowVisible = false
}

function handleHiddenTask(record) {
  isTaskShow.isShow = false
  isTaskShow.currentTask = record
  isTaskShow.showTitle = '任务隐藏'
  isTaskShow.taskShowVisible = true
  isTaskShow.text = '隐藏'
}

function handleShowTask(record) {
  isTaskShow.isShow = true
  isTaskShow.currentTask = record
  isTaskShow.showTitle = '任务恢复'
  isTaskShow.text = '恢复'
  isTaskShow.taskShowVisible = true
}

//     批量延时
const batchDelayRef = ref(null)
const batchDelay = reactive({
  delayVisible: false,
  model: {
    count: undefined
  },
  taskId: undefined
})

function handleDailyTask(record) {
  batchDelay.delayVisible = true
  batchDelay.taskId = record.taskId
}

const dailyLoading = ref(false)

function confirmDelay() {
  batchDelayRef.value.validate().then(() => {
    dailyLoading.value = true
    put(
      `/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${batchDelay.taskId}/batch_delay/${batchDelay.model.count}`
    ).then(data => {
      if (data.code === 200) {
        message.success('已提交审批，PMO操作直接生效')
        batchDelay.delayVisible = false
        batchDelayRef.value.clearValidate()
        batchDelay.model.count = undefined
        getTableData()
      } else {
        message.error(data.message)
      }

    }).finally(() => {
      dailyLoading.value = false
    })
  })
}


// 培训考试
const pxksType = ref('')
const pxState = reactive({
  title:'',
  videoVisble: false,
  pxTableLoading: false,
  videoSrc: '',
  columns:[
    {
      title: '课程名称',
      dataIndex: 'name',
      align: 'center',
      ellipsis: true,
      resizable: true,
      width: 280,
    },
    {
      title: '课程说明',
      dataIndex: 'description',
      align: 'center',
      ellipsis: true,
      resizable: true,
      width: 280,
    },
    {
      title: '课程文件',
      dataIndex: 'file',
      align: 'center',
      resizable: true,
      width: 300,
      visible: computed(() => pxksType.value==='培训')
    },
    {
      title: '视频文件',
      dataIndex: 'videoName',
      align: 'center',
      resizable: true,
      width: 300,
      visible: computed(() => pxksType.value==='培训')
    },
    {
      title: '考试链接',
      dataIndex: 'examLink',
      align: 'center',
      resizable: true,
      width: 300,
      visible: computed(() => pxksType.value==='考试')
    },
  ],
  dataSource:[],
  visible:false
})
const filteredPxksColumns = computed(() => {
  return pxState.columns
    .map(column => {
      const updatedColumn = {
        ...column
      }
      return updatedColumn.visible === false ? null : updatedColumn
    })
    .filter(Boolean)
})
function showKspx(id,type){
  pxksType.value = type
  pxState.title = type
  get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/get_milepost_train/${id}`).then(data=>{
    if (data.code !== 200) {
      message.error(data.message)
      return
    }
    pxState.dataSource = data.data||[]
    pxState.visible = true
  })
}
function handlerGetSpace1(data) {
  return data ? data.split(/[,，;；\n]/).map(item => item.trim()) : []
}
import TCPlayer from 'tcplayer.js'
import 'tcplayer.js/dist/tcplayer.min.css'
let player = ref(null) // 在外部作用域声明播放器实例
function showVideo(record) {
  console.log(record)
  pxState.videoVisble = true
  pxState.videoSrc = record
  nextTick(() => {
    localStorage.setItem('ghostWatermarkFirstShow', 0)
    let userInfo = localStorage.getItem('al__USER_INFO')
    console.log(JSON.parse(userInfo).value)
    let userName = JSON.parse(userInfo).value.name
    player.value = TCPlayer('video01', {
      sources: [
        {
          src: pxState.videoSrc // 播放地址
        }
      ],
      licenseUrl: 'https://license.vod2.myqcloud.com/license/v2/1309773370_1/v_cube.license', // license 地址，参考准备工作部分，在视立方控制台申请 license 后可获得 licenseUrl
      plugins: {
        DynamicWatermark: {
          //
          type: 'text',
          speed: 0.3, // 建议取值范围 0<= speed <=1，默认值 0.2
          content: `研究院版权所有（${userName}正在播放）`, // 添加换行符
          opacity: 0.5,
          fontSize: '12px', // type === text 时有效, 其余字段通用
          color: '#FFFFFF'
        }
      }
    })
  })
}
function closeVideo() {
  player.value?.dispose()
  pxState.videoVisble = false // 关闭弹窗
}
const isVideo = (fileType) => {
  // 判断文件类型是否为视频
  return /^video\//.test(fileType);
};
// 培训考试
let newClick= throttle(async (...params) => {
  await customFunction_6lkl42y402();
  vid_gbi1twzw5v_props.visible = true;
  await dataConnector_conn_ok1jvf9mmc()
  await dataConnector_conn_728mjfyjbs()
}, 500)

// 导出
function handlerProjectExport(type) {
  if(!taskWhState.permission){
    message.info('暂无权限')
    return
  }
  if(type==='全品明细模板'){
    get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/exportAllVarietySpecialDetails`, null, { responseType: 'arraybuffer', }).then(res => {
      downloadExcel(res, `${type}.xlsx`)
    })
  }else{
    //可能会变
    get(`/solution-ppm/api/v2/built-in-system-ppm/v2/delivery_project_template/export_all_varieties_stage/${type}`, null, { responseType: 'arraybuffer', }).then(res => {
      downloadExcel(res, `${type}.xlsx`)
    })
  }

}
// 导出
// 任务计划调整
function showTaskWhModal() {
  if (!taskWhState.permission) {
    message.info('暂无权限')
    return
  }
  taskWhState.radioValue = '基于SOP'
  taskWhState.dataSource = []
  taskWhState.visible = true
}
const newPeopleList = ref([])
onMounted(() => {
  get('/solution-ppm/api/v2/built-in-system-ppm/meeting_question/permission').then(data => {
    if (data.code !== 200) {
      message.error(data.message)
      return
    }
    taskWhState.permission = data.data
  })
  //从项目参与人中取人名让任务用


  // 交付参与人s所有人
  get('/solution-ppm/api/v2/built-in-system-ppm/pmgf/get/allUser').then(({ data }) => {
    newPeopleList.value = data.userDtoList.map(item => {
      return {
        label: item.name,
        value: item.id
      }
    })
  })
})
const taskWhState = reactive({
  visible: false,
  dataSource: [],
  radioValue: '基于SOP',
  tableLoading: false,
  tipLoading: false,
  startDate: undefined,
  permission: false
})
const taskNewColumns = ref([
  {
    title: '项目阶段',
    dataIndex: 'milepostName',
    resizable: true,
    width: '100px',
    align: 'left',
    customCell: ({ rowIndex, rowSpan, aa }) => {
      return {
        rowSpan: rowSpan,
        aaa: '44',
        style: {
          fontSize: '16px',
          color: '#262626',
          fontWeight: '600',
        }
      }
    }
  },
  {
    title: '任务名称',
    dataIndex: 'taskName',
    ellipsis: true,
    width: '250px',
    resizable: true,
    align: 'left',
    customCell: ({ level, nodeType, aa, rowIndex ,groupTask}) => {
      return {
        style: {
          paddingLeft: `${(level + 1) * 20}px`,
          color: `${groupTask ? '#3875ff' : ''}`,
        }
      }
    }
  },
  {
    title: '任务状态',
    dataIndex: 'taskStatus',

    ellipsis: false,
    width: '130px',
    align: 'left'
  },
  {
    title: '任务负责人',
    dataIndex: 'taskOwner',

    ellipsis: true,
    width: '130px',
    align: 'left'
  },
  {
    title: '任务执行人',
    dataIndex: 'taskParticipantList',

    ellipsis: true,
    width: '130px',
    align: 'left'
  },
  {
    title: '审核员',
    dataIndex: 'assessors',

    ellipsis: true,
    width: '130px',
    align: 'left'
  },
  {
    title: '计划开始',
    dataIndex: 'startTime',
    ellipsis: true,
    width: '140px',
    align: 'left'
  },
  {
    title: '计划结束',
    dataIndex: 'endTime',
    ellipsis: true,
    width: '140px',
    align: 'left'
  },
  {
    title: '实际开始',
    dataIndex: 'actualStarTime',
    resizable: true,
    ellipsis: true,
    width: '140px',
    align: 'center'
  },
  {
    title: '实际完成',
    dataIndex: 'taskFinishTime',
    ellipsis: true,
    width: '200px',
    align: 'left'
  },

  {
    title: '是否隐藏',
    dataIndex: 'isHidden',

    ellipsis: false,
    width: '100px',
    align: 'left'
  },
  {
    title: '关键路径',
    dataIndex: 'critialPath',
    ellipsis: false,
    width: '100px',
    align: 'left'
  },
  {
    title: '任务日志',
    dataIndex: 'taskLog',

    ellipsis: false,
    width: '100px',
    align: 'left'
  },
  {
    title: '风险点',
    dataIndex: 'riskContent',

    ellipsis: false,
    width: '100px',
    align: 'left'
  },
  {
    title: '积累条数',
    dataIndex: 'clinkerNumber',

    ellipsis: false,
    width: '120px',
    align: 'left'
  }
])
function getWhList() {
  if(taskWhState.radioValue==='灵活调整'){
    taskWhState.startDate = undefined
  }
  taskWhState.tableLoading = true
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/plan_adjust/search', {
    templateTaskType: templateTaskType.value,
    projectId: projectId.value,
    startTime: taskWhState.startDate //基于sop调整就传时间，灵活调整，不需要传时间
  })
    .then(data => {
      if (data.code !== 200) {
        message.error(data.message)
        return
      }
      taskWhState.dataSource = groupData(formatTableData(data.data))
      console.log(taskWhState.dataSource,'taskWhState.dataSource')
    })
    .finally(() => {
      taskWhState.tableLoading = false
    })
}
function confirmRwwh(record) {
  record.okBtnLoading = true
  taskWhState.tipLoading = true
  put('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/plan_adjust/modify', taskWhState.dataSource)
    .then(data => {
      if (data.code !== 200) {
        message.error(data.message)
        return
      }
      message.success(data.message)
      taskWhState.visible = false
      getTableData()
      taskWhState.startDate = false
    })
    .finally(() => {
      taskWhState.tipLoading = false
      record.okBtnLoading = false
    })
}
// 开始
const startLoading = ref(false)

function handleOpen(record) {
  if (record.instanceId) {
    message.info('请审批完成后再开始任务')
    return
  }
  put(`/solution-ppm/api/v2/built-in-system-ppm/refactoring_task/start_task/${record.taskId}`).then(data => {
    if (data.code !== 200) {
      message.error(data.message)
      return
    }
    message.success(data.message)
    getTableData()
  }).finally(() => {
  })
}

// 开始
// SOP
const sopId = ref(null)

function getSop() {
  const params = {
    taskName: '',
    endTime: '',
    taskOwner: '',
    taskStatusOnOrOff: 'true',
    taskStatusList: [],
    stateInput: '',
    priorityStr: '',
    milepostId: '',
    projectId: projectId.value,
    taskId: sopId.value
  }
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/search', params).then(data => {
    if (data.code === 200) {
      sopMsg.value = [data.data[0]] || []
      sopVisible.value = true
    } else {
      message.error('获取任务详情失败')
    }
  })
}

const sopVisible = ref(false)
const sopMsg = ref([])

//新完成任务弹窗内容
function formatContent(content) {
  // 将内容分割成多行
  const lines = content.split('；');
  // 将每一行包裹在 p 标签中并返回
  return lines.map(line => `<p>${line.trim()}</p>`).join('');
}

const sopList = ref(
  []
)

function handleSubmitSop() {
  const params = {
    form: [],
    sopList: sopList.value,
    taskId: current.value.taskId
  }
  params.form = [...CompletionCheckListCheckList.value]
  post('/solution-ppm/api/v2/built-in-system-ppm/delivery_task/save_standard_sop', params).then(() => {
    message.success('操作成功')
    stateLi.templateOkVisible = false
    getTableData()
  })
}

//新完成任务弹窗内容
//标签浮窗表格
// tooltip样式
const labelToolStyle = {
  maxWidth: '1000px',
}

function checkAllSelected(content) {
  for (let i = 0; i < content.length; i++) {
    if (!content[i].selected) {
      return false; // 只要有一个 selected 不为 true，就返回 false
    }
  }
  return true; // 如果所有的 selected 都为 true，返回 true
}

function cancelRwwh(record) {
  taskWhState.visible = false
  taskWhState.startDate = undefined
}
function taskStatusChange(record) {
  if (record.taskStatus === '进行中'||record.taskStatus === '未启动') {
    record.taskFinishTime = undefined
  }
  if (record.taskStatus === '未启动') {
    record.actualStarTime = undefined
  }
  let newArr = []
  taskWhState.dataSource.forEach(item=>{
    if(item.parentId===record.taskId){
      newArr.push(item)
      item.taskStatus = record.taskStatus
    }
  })
  console.log(newArr)
}
function handleResizeNewTaskColumn(w, col) {
  col.width = w;
}

// 任务计划调整
const pageType = 'deliver'
const handleStart = (record) => {
  if (record.finishPermission === false) {
    message.info('暂无权限！非该任务负责人')
  } else {
    get(`/solution-ppm/api/v2/built-in-system-ppm/delivery_task/${record.taskId}/check_condition`).then(data => {
      if (data.code === 200) {
        if (!data.data) {
          message.info('依赖任务未完成，无法开始该任务')
        } else {
          sopId.value = record.taskId
          projectId.value = record.projectId
          post(`/solution-ppm/api/v2/built-in-system-ppm/task/faq/study/search`, { taskId: record.taskId }).then(
            res => {
              message.success('已开始该任务，请及时完成任务')
              // 获取表格列表
              getTableData()
              getSop()
            }
          )
        }
      } else {
        message.error(data.message)
      }


    })


  }

}
// FAQ

const examsVisible = ref(false);
//从项目参与人中取人名让任务用
const peopleList = ref([])

// 交付参与人s所有人
function getAllJfPeople() {
  get('/solution-ppm/api/v2/built-in-system-ppm/pmgf/get/allUser').then(({ data }) => {
    peopleList.value = data.userDtoList.map(item => {
      return {
        label: item.name,
        value: item.name
      }
    })
  })
}

// --------------------------------FQA,培训----------------------------------------
const faqVisible = ref(false)
const faqColumns = ref([
  {
    title: '问题归类',
    dataIndex: 'problemClassifyName',
    align: 'center',
    resizable: true,
    width: 180,
    customCell: item => {
      const { aSpan } = item
      return {
        rowSpan: aSpan
      }
    }
  },
  {
    title: '序号',
    dataIndex: 'problemHappensNo',
    align: 'center',
    resizable: true,
    width: 180,
    customCell: item => {
      const { bSpan } = item
      return {
        rowSpan: bSpan
      }
    }
  },
  {
    title: '出现问题',
    dataIndex: 'problemHappensName',
    align: 'center',
    resizable: true,
    width: 180,
    customCell: item => {
      const { bSpan } = item
      return {
        rowSpan: bSpan
      }
    }
  },
  {
    title: '项目阶段',
    dataIndex: 'problemHappensStage',

    align: 'center',
    resizable: true,
    width: 180,
    customCell: item => {
      const { bSpan } = item
      return {
        rowSpan: bSpan
      }
    }
  },
  {
    title: '原因编号',
    dataIndex: 'flowNo',
    align: 'center',
    resizable: true,
    width: 180
  },
  {
    title: '生产流程标签',
    dataIndex: 'flowLabel',

    align: 'center',
    resizable: true,
    width: 180
  },
  {
    title: '可能原因',
    dataIndex: 'flowReason',
    align: 'center',
    resizable: true,
    width: 180
  },
  {
    title: '解决方案',
    dataIndex: 'flowSolution',

    align: 'center',
    resizable: true,
    width: 180
  },
  {
    title: '主责方',
    dataIndex: 'flowResponsibleParty',

    align: 'center',
    resizable: true,
    width: 180
  },
  {
    title: '主责部门',
    dataIndex: 'flowResponsibleDepartment',

    align: 'center',
    resizable: true,
    width: 180
  },
  {
    title: '典型案例',
    dataIndex: 'flowClassicCase',
    align: 'center',
    resizable: true,
    width: 180
  }
])
const faqDataSource = ref([])
function faqModelFun(data) {
  console.log(removeNumberPrefix(data),'data')
  window.open(`${import.meta.env.VITE_PUBLIC_PATH}/page/3000001016?id=${removeNumberPrefix(data)}&from=true`, '_blank')
}
function faqVisibleCancel(){
  faqVisible.value = false
}
// --------------------------------FQA,培训，end-----------------------------------
function removeNumberPrefix(text) {
  return text.replace(/^\d+(\.\d+)*\s*/gm, '')
}
// 优化
// 控制勾选框的显示
const showSelection = ref(false)
const selectedRowKeys = ref([]) // 当前用户勾选的 key
const initialKeynotes = new Set() // 初始状态为 “是” 的 taskId
const rowTableSelection = ref(null)


// 勾选变化时更新
const onSelectChange = (newSelectedRowKeys) => {
  selectedRowKeys.value = newSelectedRowKeys
}

// 触发按钮逻辑：编辑 或 提交
const toggleSelection = () => {
  if (!showSelection.value) {
    // 开启编辑状态，记录初始选中项
    showSelection.value = true
    const keynoteTasks = stateLi.dataList.filter(item => item.keynote === '是').map(item => item.taskId)
    selectedRowKeys.value = keynoteTasks
    initialKeynotes.clear()
    keynoteTasks.forEach(taskId => initialKeynotes.add(taskId))

    // 启用勾选功能
    rowTableSelection.value = {
      type: 'checkbox',
      selectedRowKeys: selectedRowKeys.value,
      onChange: onSelectChange
    }
  } else {
    // 提交逻辑
    const added = selectedRowKeys.value.filter(id => !initialKeynotes.has(id))
    const removed = Array.from(initialKeynotes).filter(id => !selectedRowKeys.value.includes(id))

    put(`/solution-ppm/api/v2/built-in-system-ppm/v2/platform/keynote_task/${projectId.value}`, {
      addedKeynotes: added,
      removedKeynotes: removed
    }).then(data => {
      if (data.code !== 200) {
        message.error(data.message)
        return
      }
      message.success(data.message)
      getTableData()
    }).finally(() => {

      showSelection.value = false
      selectedRowKeys.value = []
      initialKeynotes.clear()
      rowTableSelection.value = null
    })
  }
}
// 监听 selectedRowKeys 变化，确保 rowSelection 同步更新
watch(selectedRowKeys, (newSelectedRowKeys) => {
  if (showSelection.value) {
    rowTableSelection.value = {
      type: 'checkbox',
      selectedRowKeys: newSelectedRowKeys, // 更新 rowSelection 的 selectedRowKeys
      onChange: onSelectChange
    };
  }
});
// 优化
function getStatusColor(status) {
  return colorMap[status] || '#9DBAFF'
}
const colorMap = {
  '进行中': '#3875FF',
  '审批中': '#1890FF',
  '未启动': '#BBBBBB',
  '完成': '#52C41A',
  '下线': '#FAAD14',
  '延期完成': '#FA8C16',
  '测试中': '#A0D911',
  '延期': '#FA3D16',
}
// 自动化任务完成

// 自动化任务提交审批
const autoTask = ref({})
function autoComplateSubmit(){
  templateOkDisabled.value = true
  post("/solution-ppm/api/v2/built-in-system-ppm/delivery_task/attachmentUploading", {
    ppmEnclosureInfoList: stateLi.fileList,
    taskId: autoTask.value.taskId
  }).then(data => {
    if (data.code === 200) {
      post('/solution-ppm/api/v2/built-in-system-ppm/third_task/completion',{
        taskId:autoTask.value.taskId,
        actualStartTime: jfMbActualFinishTime.value,
        repParams:statuState.repParams
      }).then(data=>{
        if(data.code!==200){
          message.error(data.message)
          return
        }
        message.success(data.message)
        cancelAutoComplate()
        getTableData();
      }).finally(()=>{
        templateOkDisabled.value = false
      })
    } else {
      templateOkDisabled.value = false
      message.error('附件上传失败')
    }
  })

}
function cancelAutoComplate(){
  statuState.autComplateVisible = false
  autoTask.value = {}
  statuState.repParams = undefined
  statuState.radioValue = '默认参数'
  jfMbActualFinishTime.value = undefined
}
function autoRadioChange(){
  if(statuState.radioValue==='默认参数'){
    statuState.repParams = undefined
  }else{
    statuState.repParams = autoTask.value.verifyRepParams
  }
}
</script>
<style lang="less" scoped>
.page_root {
  overflow: hidden !important;
}

.mr10 {
  margin-right: 20px;
}

.ml10 {
  margin-left: 20px;
}
/* 里程碑进度css。 */
.content-box {
  display: flex;
  flex-direction: row;
}

.content-box .right-table {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.right-table .search {
  background: #fff;
}

.right-table.table-box {
  flex: 1;
  background: #fff;
  padding: 10px;
}

.mt15 {
  margin-top: 15px !important;
}

.mr16 {
  margin-right: 20px;
}

/deep/ .my-page .aps-picker,
/deep/ .ant3-picker {
  width: 100%;
}
.modal-form-keynote :deep(.ant3-form-item-label){
  width: 145px;
}
/deep/ .one-line .ant3-form-item-control,
/deep/ .one-line .aps-form-item-control {
  max-width: unset !important;
}

.del {
  width: 66px;
  color: #3875ff;
  float: right;
}

.form-content {
  display: inline-block;
  width: calc(100% - 80px);
}

.edit-form-content {
  width: 100%;
}

.form-item {
  border-bottom: 1px solid #e5e7eb;

  &:not(:first-child) {
    margin: 20px 0 0;
  }
}

.add-btn {
  margin-top: 20px;
}

.fr {
  float: right !important;
}

/deep/ .ant3-spin-nested-loading,
/deep/ .ant3-spin-container {
  width: 100%;
  overflow: hidden;
}

.checkbox-group {
  margin: 10px 0;
  white-space: normal;
}

.checkbox-group .label {
  font-size: 16px;
  line-height: 1.4em;
  color: #3875ff;
  border-left: 6px solid #3875ff;
  text-indent: 8px;
  margin: 8px 0;
}

.new-check .label {
  font-size: 16px;
  line-height: 1.4em;
  color: #3875ff;
  border-left: 6px solid #3875ff;
  text-indent: 8px;
  margin: 8px 0;
}

.checkbox-group label {
  width: 100%;
  padding-left: 10px;
}

.checkbox-group /deep/ .aps-checkbox-wrapper + .aps-checkbox-wrapper,
.checkbox-group /deep/ .ant3-checkbox-wrapper + .ant3-checkbox-wrapper {
  margin-left: 0;
}

.ant3-table-thead > tr > th,
/deep/ .ant3-table-thead > tr > th,
/deep/ .aps-table-thead > tr > th {
  background-color: #3875ff;
  color: #fff;
  font-weight: 600;
  padding: 14px 16px;
  border-bottom: 1px solid #3875ff
}

/deep/ .ant3-table.ant3-table-bordered > .ant3-table-container > .ant3-table-body > table > tbody > tr > td {
  border: 1px solid #d9d9d9;
  color: #262626;
  border-left: none;
}

/deep/ .table-striped td {
  background-color: #fafafa;
}

.table-form-box {
  margin: 20px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.table-form-box > span {
  padding-left: 8px;
  line-height: 21px;
  font-weight: 600;
  font-size: 16px;
  border-left-style: solid;
  border-left-width: 4px;
  border-left-color: #3875ff;
}

.content-box .right-table .search {
  background: #fff;
}


/deep/ .aps-table-thead > tr,
/deep/ .ant3-table-thead > tr {
  line-height: 12px;
}

/deep/ .event-page .ant3-table-tbody td,
/deep/ .my-page .aps-table-tbody td,
/deep/ .my-page .ant3-table-tbody td {
  padding: 0 16px;
}

/deep/ .ant3-table-tbody tr {
  line-height: 22px;
  height: 40px;
}

:deep(.@{ant-prefix}-table-empty .@{ant-prefix}-table-tbody tr > td) {
  padding: 0;
}

.hide {
  display: none;
}
.task-name {
  display: flex;
  align-items: center;
  gap: 8px;              /* 标签与内容间距 */
  overflow: hidden;       /* 超出隐藏 */
}

.task-tags {
  display: flex;   /* 多个标签间距 */
  flex-shrink: 0;         /* 标签不被压缩 */
  white-space: nowrap;    /* 标签始终在一行 */
  gap: 2px;
}

.task-name-title {
  flex: 1;                /* 占据剩余空间 */
  overflow: hidden;
  text-overflow: ellipsis;/* 超出显示省略号 */
  white-space: nowrap;    /* 禁止换行 */
}
.task-name-title {
  display: inlie-block;
  min-width: 50px;
}

.finish-standard {
  display: inlie-block;
  min-width: 70px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.table-box {
  flex: 1;
  background: #fff;
  padding: 10px;
}
.task-dependency {
  white-space: pre-wrap;
}

.sop-btn {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
}
.one-line-sop {
  display: flex;
  min-height: 40px;
  line-height: 40px;
  border: 1px solid #afc8ff;
}

.one-left {
  background-color: #ebf1ff;
  width: 150px;
  padding: 0 7px;
  text-align: right;
}

.one-right {
  padding: 0 7px;
  flex: 1;
  border-left: 1px solid #afc8ff;
}

.one-line-sop,
.two-line-sop {
  font-family: PingFangSC-Regular;
  font-size: 14px;
  color: #262626;
  letter-spacing: 0;
  font-weight: 400;
}

.two-line-sop {
  border: 1px solid #afc8ff;
  display: flex;
  height: 40px;
  line-height: 40px;
}

.two-item {
  display: flex;
  width: 50%;
}

.two-left {
  padding: 0 7px;
  text-align: right;
  width: 150px;
  background-color: #ebf1ff;
}
.two-right {
  border-left: 1px solid #afc8ff;
  border-right: 1px solid #afc8ff;
  flex: 1;
  padding: 0 7px;
}
.sop-div {
  min-height: 300px;
  max-height: 650px;
  overflow: auto;
  margin-bottom: 40px
}
/*关键路径*/

.critical-path{
  height: 20px;
  width: 20px;
  background-image: url('http://10.40.0.33:9001/file-storage/528348581051316224-source.png');
  background-size: cover;
}
.task-milestone {
  color: #3875ff;
  font-weight: 600;
}
.task-first {
  color: #3875ff;
  font-weight: 600;
}

.task-over {
  color: #e91afb;
  font-weight: 600;
}
.del {
  width: 66px;
  color: #3875ff;
  float: right;
}
/*样式*/
.batch-line{
  width: 100%;
  border-top: 1px solid #d9d9d9;
  margin: 16px 0;
}
.task-collaborate{
  width: 58px;
  text-align: center;
  height: 16px;
  line-height: 16px;
  position: absolute;
  top: 12px;
  left: 9px;
  background-color: #EEE5FA;
  color: #9254DE;
}
.task-name-title-right{
  margin-left: 80px;
}

/*新需求*/
.content-box .right-table .search {
  background: #fff;
  margin-bottom: 16px;
}
.content-box .right-table .search-top {
  background: #fff;
  padding-top: 10px;
}
.my-page .table-box{
  padding:16px 24px;
  box-shadow: 0 0 10px 0 rgba(0,0,0,0.10);
  border-radius: 4px;
  margin-bottom: 16px;
}
:deep(.ant3-tabs > .ant3-tabs-nav, .ant3-tabs > div > .ant3-tabs-nav){
  margin-bottom:8px
}

.my-page{
  height: calc(100vh - 185px);
  overflow: hidden;
}
.file-item{
  color:#3875ff;
  cursor:pointer;
  margin: 10px 0 ;
}
.content-box .right-table .search{
  box-shadow:none;
  margin-bottom:4px;
}
.my-page .table-box{
  padding:16px 24px;
  box-shadow:none;
  padding-top: 0;
  border-radius: 4px;
  margin-bottom: 16px;
  padding-left: 0;
  padding-right: 0;
}
.content-box .right-table .search{
  padding-left: 0;
  padding-right: 0;
}
/*任务优化*/
/*动态角色*/
.pj-title{
  display: flex;
  justify-content: space-between;
}
:deep(.role-content .ant3-form-item-label) {
  width: 80px !important;
}
:deep(.ys-content .ant3-form-item-label) {
  width: 115px !important;
}
.role-item{
  display: flex;
}
.role-label{
  color:#595959;
}
.role-value{
  color:#3875ff;
  font-weight: 600;
}
.role-content-detail{
  min-width:100%;
}
/*动态角色*/
/*培训考试*/
.px-default-table:deep(.@{ant-prefix}-table-thead) > tr > th {
  background-color: #3875ff;
  color: #fff;
  font-weight: 600;
  padding: 8px 16px;
  border-right: 1px solid #d9d9d9;
}
.px-default-table:deep(.@{ant-prefix}-table-tbody) tr > td {
  font-size: 14px;
  font-family: arial, helvetica, 'microsoft yahei';
  font-weight: 400;
  color: #262626;
  padding: 8px 8px;
  border-bottom: 1px solid #d9d9d9;
  word-break: break-all;
}
.videolinks {
  width: 300px;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #3875ff;
}

/*培训考试*/

/*新需求任务计划调整维护*/
.task-new-table-box {
  border-radius: 2px;
  background-color: #fff;
}
.task-new-table-box:deep(.@{ant-prefix}-table-thead) > tr > th {
  background: #3875ff;
  color: #fff;
  font-weight: 600;
  padding: 8px 12px;
  border-right: 1px solid #d9d9d9 !important;
  position: relative;
}
.task-new-table-box :deep(.@{ant-prefix}-table-tbody) tr > td {
  font-size: 14px;
  font-family: arial, helvetica, 'microsoft yahei';
  font-weight: 400;
  color: #262626;
  border-bottom: 1px solid #d9d9d9;
  padding: 8px 12px;
  word-break: break-all;
}
.task-new-table-box :deep(.ant3-table-column-sorter-inner) {
  position: relative;
  left: -5px;
}

/*新需求任务计划调整维护*/


.modal-form :deep(.ant3-form-item-label){
  width: 155px;
}
.table-top{
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.table-title{
  height: 16px;
  line-height: 16px;
  font-size: 16px;
  font-weight: 600;
  padding-left: 8px;
  border-left: 4px solid #3875ff;
}
.table-top-right{
  display: flex;
  justify-content: space-between;
}
.edit-form :deep(.ant3-form-item-label){
  width: 115px;
}
.status-tag {
  display: inline-block;       /* 必须 inline-block 或 inline-flex 才能自适应宽度 */
  font-size: 14px;
  color: #ffffff;
  letter-spacing: 0;
  text-align: center;
  line-height: 22px;
  font-weight: 500;
  height: 22px;
  border-radius: 2px;
  padding: 0 8px;              /* 左右内边距，保证文字不贴边 */
  white-space: nowrap;          /* 防止文字换行 */
  margin: 0 auto;
}

.task-name-title-new {
  display: inline-block;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  min-width: 50px;
}
.milepost-name-opration :deep(.ant3-btn){
  margin: 0 2px !important;
  padding: 0;
  font-weight: 600;
}
</style>
